this is how I display the user’s email in my dropdown
<%= collection_select(:user, :id, User.all(:conditions => ["company_name=?", $company]), :user_id, :email, :prompt=>'Select a User') %>
this is the parameters being generated:
Parameters: {"commit"=>"Submit", "utf8"=>"✓", "from_date"=>"December 7, 2011 6:45 AM", "to_date"=>"December 9, 2011 7:45 AM", "user"=>{"user_id"=>"12"}}
Once hitting the submit button it has to display the details with the help of user_id and my index function of the controller looks like this
def index
if (!params[:user][:user_id].nil?)
user_id = params[:user][:user_id]
else
user_id = current_user.id
end
But I get an error like this:
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.[]
What could be wrong please help
thanks in advance
if params[:user] is nil the “params[:user][:user_id].nil raise exeption” need: