我一直在嘗試最近顯示的列表提交表單時成功修改的字段。唯一的問題是,我的表單(我使用簡單的表單)沒有顯示錯誤,當有一些表單無法提交。簡單的形式問題與Rails 3
這裏是我的代碼簡化:
def update
@wizard.assign_attributes(params[:wizard])
# Get changed attributes
if @wizard.save
# Set the success flash with fields modified
redirect_to @wizard
else
@title = "Edition du profil"
render 'edit'
end
end
的觀點:
<%= simple_form_for @wizard do |f| %>
<%= f.input :email %>
<%= f.input :story %>
<%= f.submit "Modifier", :class => "btn success small" %>
<% end %>
型號:
class Wizard < ActiveRecord::Base
has_secure_password
attr_accessible :email, :story, :password, :password_confirmation, :password_digest
serialize :ranks, Array
validates_presence_of :email, :first_name, :last_name, :gender, :story
validates_presence_of :password, :password_confirmation, :unless => Proc.new { |w| w.password_digest.present? }
# Other validations here
has_one :subject, :foreign_key => "teacher_id"
ROLES = %w[teacher]
scope :with_role, lambda { |role| {:conditions => "roles_bitmask & #{2**ROLES.index(role.to_s)} > 0"} }
# Other functions here
end
有沒有人的想法?
預先感謝您!
你應該發佈你的視圖代碼。 –
好的,這是張 – Cydonia7
你從哪裏得到'assign_attributes'(它是rails 3.1特有的,'update_attributes'在以前的版本中更常用)?你在嚮導上進行大規模分配嗎? –