我有在我看来,下面的代码:Ruby on Rails的params为无
<%= form_for :command_selected, :method => "get", :url => {:action => "command_domain_selected"} do |f| %>
<%= f.submit "Make Deployment" %>
<%= f.radio_button :domain, '1dev-den' %> <%= label :domain, '1dev-den'%><br />
<%= f.radio_button :domain, '2dev-den' %> <%= label :domain, '2dev-den'%><br />
当我在submit (make deployment)
按钮点击,从submit button
和radio button
parameters
都到行动mentiond在form_for
通过以上。但是如果我没有选择任何单选按钮并在提交时选中,它会抛出(无返回的对象,您可能期望有一个数组实例)错误。但是,我想测试参数是否在我的动作中,并重定向到其他视图。下面是我的行动
def command_domain_selected
if(params[:command_selected][:domain].nil?)
respond_to do |format|
format.html{redirect_to wrong_selection_path}
end
else
@command_selected = params[:commit]
@domain_selected = params[:command_selected][:domain]
end
end
为什么连抛了零对象错误时,即时通讯手之前检查它的代码? 请帮助
Update: Below is the error i'm getting
NoMethodError in AuthorizationController#command_domain_selected
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]Rails.root: c:/Final/authorize
Parameters:
{"utf8"=>"✓", "commit"=>"Make Deployment"}
向我们显示错误 – keymone
@keymone这里是错误NoMethodError在AuthorizationController#command_domain_selected 你有一个没有对象,当你没有想到它! 您可能预期了Array的一个实例。 评估nil时出错[] Rails.root:c:/ Final/authorize Application Trace |框架跟踪|完整跟踪 app/controllers/authorization_controller.rb:43:在'command_domain_selected' – user1455116
作为标准约定,默认情况下应该选择其中一个单选按钮。 –