Ruby on rails CanTango是如何工作的?
我是Rails的新手,我需要你的帮助 我有这个:Ruby on rails CanTango是如何工作的?,ruby-on-rails,Ruby On Rails,我是Rails的新手,我需要你的帮助 我有这个: # config/initializers/cantango.rb CanTango.config do |config| config.engines.all :on # more configuration here... end # app/models.User.rb class User < ActiveRecord::Base def roles_list roles_rel = Role.where(:u
# config/initializers/cantango.rb
CanTango.config do |config|
config.engines.all :on
# more configuration here...
end
# app/models.User.rb
class User < ActiveRecord::Base
def roles_list
roles_rel = Role.where(:user_id=>self.id)
roles=[]
roles_rel.each do |x|
roles.push(x.name)
end
return roles #return [":reader","writer"] from database
end
end
# app/permits/reader_permits.rb
class ReaderPermit < CanTango::UserPermit
def initialize ability
super
end
protected
def permit_rules
can :read, :all
end
end
#config/initializers/cantango.rb
CanTango.config do | config|
config.engines.all:打开
#更多配置在这里。。。
终止
#app/models.User.rb
类用户self.id)
角色=[]
角色_rel.each do | x|
角色推送(x.name)
终止
返回角色#从数据库返回[“:reader”,“writer”]
终止
终止
#app/permissions/reader_permissions.rb
类ReaderPermit
在我看来,我有
<%= link_to 'readddd', "/news/feed/read_full?s=#{g.id}&page_id=#{params[:page_id]}" if user_can?(:read, Newsfeed)%>
但是对于#
请给我一个非常简单的解释我的情况,在哪里和我必须写什么。GitHub对我没有帮助。在这里暂停教程:
我想你忘记了:创建并注册一个用户模型
首先,您必须有一个用户模型。使用tango_用户宏来
向CanTango注册用户类。然后,CanTango将生成用户
API方法,如#用户#可以吗?对于用户类,admin\u可以吗?暂时
注册管理员用户类等
class User
# register as a "user class" for CanTango
tango_user
end