控制器中的 -Form_html.erb、routes.rb 和 create 方法如下。但是在提交表单时,它在我使用 params[:mail_setting] 的那一刻给出了 nil 类错误
routes.rb
-----------
resources :mail_settings
the _form.html.erb
---------
<%= form_tag '/mail_settings' do %>
<div class="fieldBlock">
<%= label_tag :name %> <%= text_field_tag :name%> </div>
<div class="fieldBlock">
<%= label_tag :id%> <%= text_field_tag :id%> </div>
<div class="actions fieldBlock">
<%= submit_tag "Update Settings ", :class => "btn-large btn-success" %>
</div>
<% end %>
控制器中的create方法:
def create
@mail_setting = MailSetting.find_by_user_id_and_name(current_user.id, params[:mail_setting][:name])
if ! @mail_setting.blank?
@mail_setting.update_attributes(params[:mail_setting])
else
@mail_setting = MailSetting.new(params[:mail_setting])
@mail_setting.save
render action: "index"
end
end