简单的形式问题与Rails 3
我一直在尝试最近显示的列表提交表单时成功修改的字段。唯一的问题是,我的表单(我使用简单的表单)没有显示错误,当有一些表单无法提交。简单的形式问题与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
有没有人的想法?
预先感谢您!
它可能与您如何覆盖AR有关。我记得一些插件遇到assign_attributes问题。同时你可以尝试:
@wizard.assign_attributes(params[:wizard], :without_protection => true)
如果这样做的话,它至少可以将问题缩小到质量分配。
实际上,我解决了在fieldset_tag中封装表单中文件的问题。我只是不明白为什么。 – Cydonia7
您可能会在编辑/新视图时丢失此零件。其中@wizard
是您的型号名称。 在表单标签中写下这段代码。
<% if @wizard.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@wizard.errors.count, "error") %> prohibited this task from being saved:</h2>
<ul>
<% @wizard.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
事实上,在我的其他形式,简单的形式自动使用我自己的CSS样式等。我在寻找的是这里不属于这种情况的原因。 – Cydonia7
post ur查看代码 –
你应该发布你的视图代码。 –
好的,这是张 – Cydonia7
你从哪里得到'assign_attributes'(它是rails 3.1特有的,'update_attributes'在以前的版本中更常用)?你在向导上进行大规模分配吗? –