Note that there are some explanatory texts on larger screens.

plurals
  1. POruby on rails params is nil
    text
    copied!<p>I'm having the following code in my view:</p> <pre><code>&lt;%= form_for :command_selected, :method =&gt; "get", :url =&gt; {:action =&gt; "command_domain_selected"} do |f| %&gt; &lt;%= f.submit "Make Deployment" %&gt; &lt;%= f.radio_button :domain, '1dev-den' %&gt; &lt;%= label :domain, '1dev-den'%&gt;&lt;br /&gt; &lt;%= f.radio_button :domain, '2dev-den' %&gt; &lt;%= label :domain, '2dev-den'%&gt;&lt;br /&gt; </code></pre> <p>When i click on the <code>submit (make deployment)</code> button, <code>parameters</code> from <code>submit button</code> and <code>radio button</code> are passed on to the action mentiond in the <code>form_for</code> above. But if i do not select any radio button and cilck on submit, it throws the (nil object returned you might be expecting an instance of array) error. However, i want to test if the parameter is nil in my action and redirect to some other view. Below is my code for the action</p> <pre><code>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 </code></pre> <p>Why is it throwing the nil object error even when im checking it before hand? Please help</p> <pre><code>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"=&gt;"✓", "commit"=&gt;"Make Deployment"} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload