【发布时间】:2013-01-30 17:30:40
【问题描述】:
即使已添加 attr_accessible 属性,也无法批量分配 :title、:url 和 :about .在 Rails 控制台上可以,但在在线表单上不行。
帖子模型:
class Post < ActiveRecord::Base
attr_accessible :about, :downv, :names, :points, :title, :upv, :url, :user_id
belongs_to :user
end
用户模型:
class User < ActiveRecord::Base
attr_accessible :email, :password_digest, :post_id, :password, :password_confirmation, :name
has_many :posts
has_secure_password
validates_presence_of :password, :on => :create
end
创建后控制器:
def create
@post = User.new(params[:post])
@post.upv, @post.downv, @post.points = 0, 0, 0
@post.user_id = params[:user_id]
@post.names = ""
if @post.save
redirect_to root_url, notice: "Post created."
else
render "new"
end
end
我的表单视图与任何其他表单视图一样。
【问题讨论】:
标签: attr-accessible