Gem Homeland - 嵌入式的论坛组件

huacnlee · 2012年04月17日 · 最后由 babyhai 回复于 2018年01月18日 · 7580 次阅读

越来越发现,我的每个项目中都需要类是 Ruby China 或 V2EX 这样的论坛功能,用于用户反馈讨论什么的,之前一直是拷贝代码来实现。

最近将 Homeland 改成了可以嵌入到任何项目的 Gem,它可以像 Devise 一样直接签入到任何系统中(目前只有 Mongoid 支持,后面会实现 ActiveRecord)。

https://github.com/huacnlee/homeland

安装

加入 gem Gemfile

gem "homeland"


然后

$ rails g homeland:install


还需要调整一下 application.html.erb 里面有连接的地方 before:

<%= link_to "Home", root_path %>
<%= link_to "Posts", posts_path %>


after:

<%= link_to "Home", main_app.root_path %>
<%= link_to "Home", main_app.posts_path %>


routes.rb 里面加入:

mount Homeland::Engine, :at => "/bbs"


application.js 里面引入

/*
 *= require homeland
 */

application.css 里面引入

/*
 *= require homeland
 */


然后你就可以输入 /bbs 打开论坛了

定制 Views

如果你想自己调整 View 结构的话,你可以用这个命令把 View 生成出来:

$ rails g homeland:views


然后修改 app/views/homeland/ 里面的文件

有木有考虑把目前的 ruby-china 给镶进去~?

#1 楼 @huobazi Ruby China 有太多特性,不适合每个项目,还是之前那种简单的方式满足需求

cool, 是不是可以看看和这个有什么异同: https://github.com/radar/forem

我也是有参考 forem 的设计方式,只是他的功能不是我喜欢的 在线演示 http://imax.im/bbs/

看来 @huacnlee 做了不少站啊

很棒!我也打算这么搞,到时候参考一下 Homeland。

holy crap! 我的 rails 启蒙项目。

很赞!超级实用的东东,谢谢 @huacnlee

很不错。过几天去看下

好厉害。mark 一下,以后实践

我想知道那个“盛大云”还有“图片存储由 又拍云存储 提供”是不是意味着这两个都不用花钱由提供商赞助的??

和 ruby-china 这套代码搭配时候问题不少,主要是缓存有交错,在个人页面也相应出现问题。

这个是我想要的东西

什么时候实现 ActiveRecord 呀:)

安装完运行后,点击发布新帖,报下面这个错误,怎么弄啊? NoMethodError in Homeland::TopicsController#new

undefined method `require_user' for #Homeland::TopicsController:0xbb3a5a0

/Users/SanviLu/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant User (NameError)

#18 楼 @sword721 打开 config/initializes/homeland.rb 修改那几个配置参数

也就是这么个文件:https://github.com/huacnlee/homeland/blob/master/lib/generators/homeland/install/templates/initializer.rb

此文件是用于申明一些 Homeland 需要的方法

你这个是需要给 Homeland.require_user_method 设定一个方法名(这个方法名需要再 ApplicationController.rb 里面又定义的)

#20 楼 @huacnlee

1.改了代码,把 account 改回了默认的 user,可以成功安装 2.面包屑如何增加? 我在 application.html.erb 增加了 <%= render_breadcrumb %> ,好像没效果,只能看到 home 3.kaminari 和 will_paginate 冲突的问题,fork 一份出来修改源码 4.节点的统计失效,共有 0 个讨论主题 5.@ 有什么效果?

这个还有在维护么?demo 看不了

#19 楼 @sanivbyfish 您好,我也遇到了和您一样的问题 /Users/zhangxiaodong/.rvm/gems/ruby-2.2.0/gems/activesupport-4.2.5.1/lib/active_support/inflector/methods.rb:261:inconst_get': uninitialized constant User (NameError)` 我更换了 monogid 环境,还没有解决,上面说是我的 user 问题,我是新手不是很理解,请问下该怎么解决?

#19 楼 @sanivbyfish 谢谢,我找到答案了,我没有用 devise install a User system.创建用户后,运行通过了。

Peter Homeland ?! 提及了此话题。 11月15日 05:05

访问 127.0.0.1:3000:

Showing /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/homeland-1.0.1/app/views/layouts/homeland/application.html.erb where line #5 raised:

couldn't find file 'homeland' with type 'application/javascript'
Checked in these paths: 
//= require_tree .
/*
 *= require homeland
 */
kenneth 按教程安装 Homeland 出错,不知道为啥? 提及了此话题。 04月03日 10:56
需要 登录 后方可回复, 如果你还没有账号请 注册新账号