开发者

How does CanTango work?

I am new to Rails and I need your help.

I have this:

# 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

In my view I have

<%= link_to 'readddd', "/news/feed/read_full?s=#{g.id}&page_id=#{params[:page_id]}" if user_can?(:read, News开发者_C百科feed)%>

but I get an error undefined method 'user_can?' for #<#<Class:0xaf41f50>:0xaf40eac>

Please give me a very simple explanation for my situation, where and what I must write. GitHub doesn't help me.


Fallow the tutorial here: https://github.com/kristianmandrup/cantango/wiki/Quickstart

I think you forgot this: Create and register a User model

First you must have a User model. Use the tango_user macro in order to register a user class with CanTango. CanTango will then generate User APIs methods such as #user_can? for the User class, admin_can? for a registered Admin user class etc.

class User
  # register as a "user class" for CanTango
  tango_user
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜