Ruby on rails 在rails中保存单选按钮值
我正在尝试在rails应用程序中使用单选按钮。目前,按钮按预期显示在页面上,但提交时未保存值。我想问题其实出在我的提交按钮上——按下按钮时什么也没发生 以下是带有单选按钮的“我的页面”代码:Ruby on rails 在rails中保存单选按钮值,ruby-on-rails,radio-button,form-for,submit-button,Ruby On Rails,Radio Button,Form For,Submit Button,我正在尝试在rails应用程序中使用单选按钮。目前,按钮按预期显示在页面上,但提交时未保存值。我想问题其实出在我的提交按钮上——按下按钮时什么也没发生 以下是带有单选按钮的“我的页面”代码: <div class="form_row> <%= form_for @term, :url=>{ :action =>"update_status" } do |f| %> <%= f.radio_button :status, 'on' %><b
<div class="form_row>
<%= form_for @term, :url=>{ :action =>"update_status" } do |f| %>
<%= f.radio_button :status, 'on' %><b>On</b> <br/>
<%= f.radio_button :status, 'off' %><b>Off</b> <br/>
<%= f.radio_button :status, 'leave' %><b>Leave</b> <br/>
<div class="actions">
<%= f.submit "Change term status" %>
</div>
<% end %>
</div>
以下是两种定义:
def update
@term = Term.find(params[:id])
@dplan=@term.dplan
if @term.update_attributes(params[:term])
flash[:success] = "Edit successful."
redirect_to @dplan
else
flash[:success] = "Error"
redirect_to @dplan
end
end
def update_status
@term = Term.find(params[:id])
@dplan=@term.dplan
if @term.update_attributes(params[:term])
flash[:success] = "Term status changed."
redirect_to @term
else
flash[:success] = "Error"
redirect_to @term
end
end
谢谢大家! 我认为你的
表单中的调用有一个错误:没有使用:url=>{:actions=>“update\u status”}
应该是:url=>{:action=>“update\u status”}
我认为你的表单中的调用有一个错误:没有使用:url=>{:actions=>“update\u status”}
应该是:url=>{:action=>“update_status”}
多亏了!我想当你试图在一个页面上使用两个表单时,会发生一些奇怪的事情,最好的方法是合并表单,但在我的术语controllerupdate
definition中使用if语句来区分这两个按钮。谢谢你的帮助 多亏了!我想当你试图在一个页面上使用两个表单时,会发生一些奇怪的事情,最好的方法是合并表单,但在我的术语controllerupdate
definition中使用if语句来区分这两个按钮。谢谢你的帮助 你的代码对我有用。你有更多的信息吗?日志是否显示请求是以预期值发布的?对不起,我对这个有点陌生-日志是什么?你的代码对我有用。你有更多的信息吗?日志是否显示请求是以预期值发布的?对不起,我对这个有点陌生-日志是什么?你是对的,我确实有那个输入错误,但出于某种原因它仍然不起作用!是否使用attr\u受保护
或attr\u可访问
调用?也许问题出在模型内部。你是对的,我确实有打字错误,但出于某种原因,它仍然不起作用!是否使用attr\u受保护
或attr\u可访问
调用?也许问题出在模型内部。
def update
@term = Term.find(params[:id])
@dplan=@term.dplan
if @term.update_attributes(params[:term])
flash[:success] = "Edit successful."
redirect_to @dplan
else
flash[:success] = "Error"
redirect_to @dplan
end
end
def update_status
@term = Term.find(params[:id])
@dplan=@term.dplan
if @term.update_attributes(params[:term])
flash[:success] = "Term status changed."
redirect_to @term
else
flash[:success] = "Error"
redirect_to @term
end
end