我正在尝试让令牌字段在我的应用上运行.
我完全按照这个视频:http://railscasts.com/episodes/258-token-fields
项目模型
class Project < ActiveRecord::Base
attr_accessible :edited_first_name, :edited_last_name, :first_name, :last_name, :business_div, :client, :customer_benifits, :edited_date, :end_date, :entry_date, :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, :role, :start_date, :status, :summary, :tech , :technols, :technol_tokens
has_many :projecttechnols
has_many :technols, :through => :projecttechnols
attr_reader :technol_tokens
def technol_tokens=(ids)
self.technol_ids = ids.split(",")
end
accepts_nested_attributes_for(:technols)
Run Code Online (Sandbox Code Playgroud)
技术控制器:
def index
@technols = Technol.where("tech like ?", "%#{params[:q]}%")
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @technols.map(&:attributes) }
end
end
Run Code Online (Sandbox Code Playgroud)
布局/ application.html.erb
<!DOCTYPE html>
<html> …Run Code Online (Sandbox Code Playgroud) 我正在使用rolify来管理用户角色,当我尝试通过用户表单更新角色时,我会收到:
can't mass-assign protected attributes: role_ids
Run Code Online (Sandbox Code Playgroud)
这很令人欣慰,但我想知道,如何允许管理员通过批量分配更新用户角色但不允许普通用户?
我已经开始学习Rails 3.0,并决定花一些时间学习Pure Ruby 1.9,并想知道是否有办法查看对象类,因为它始终可用.就像是有一个你可以输入IRB的命令,例如,它将显示对象类中的所有方法,如to_a,to_s等.感谢您的帮助
安Item has_many Pieces.我有两种方法,一种可以找出这件作品是否可用,另一种可以找出一件作品是否有可用的作品.
# in piece.rb
def available?(current_user, piece)
if piece.status == 1
true
elsif piece.status == 2
false
elsif piece.status == 3
true if piece.friend_id == current_user.id
end
end
#in item.rb
def available?(current_user, user, item)
false
item.pieces.each do |piece|
if piece.available?(current_user, piece)
true
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的available?方法Item是错的.我希望它返回,true如果Item有可用pieces,false如果没有.我的代码背后的理论是该方法返回,false除非有一个返回的片断true.当我在控制台中执行此操作时,我得到的是散列中的碎片,而不是真或假.
任何人都可以解决我的问题或告诉我更好的方法吗?