I’ve got a generator form_tag where I have checkboxes. I’m not saving these records to the db, but I want to operate on them, so I’ve got i my ‘create’ method:
...
def create
@generator = Generator.new(params[:generator])
@fname = @generator[:fname]
redirect_to generators_show_path
...
where ‘fname’ is one of the checkboxes 😉
And I’ve got in ‘show’ file:
<p>
<b>Fname:</b>
<% if @fname.nil? %>
fname is nil!
<% else %>
fname has a value:D
<% end %>
</p>
But every time fname is nil! why?? 🙁
It seems that you set
@fnamein actioncreateand then redirect to actionshow(where the view gets rendered).When a redirection happens, the current request (existing as an instance of your controller) is finished, and a new request is made – which does not share
@fnamewith the previous one.Therefore, if you want to get the value of @fname right, you should either render the view in action
createor set@fnamein actionshow.