I have a model ("Ups") and a corresponding controller
("UpsController"). The Ups model has a link to my "channels" toble
through channel_id
Everything I am going to do in the given views for Ups have to do with
using those ups from a selected channel. Thus, I am putting a partial
at the top of the views, with a select box to choose the channels:
My question is, within my UpsController.newchannel(), how do I access
the calue of the channel_id that has been selected in the form
submission?
Incidentally, if you look at the erb code I put above, there is a line
feed that gets inserted after the submit button, before the next
section " links_for_uplog " within the div. How can I not have that?
And then in the controller:
@channels = Channel.not_deleted
Then in your view:
<%= f.select :channel_id, @channels %>
The standard here would be to create the new Ups in a method called
create. By using form_for on a new record rails will automatically
know to post to an action called create so, unless you have a good
reason not to, I'd recommend calling your controller method "create"
and letting Rails behave the way it wants to.
Thank you. But suppose I didn't use a named scope -- in that case, how
then could I refer to it in my controller? (though I will follow your
advice and use the named scope, I need to know the other way also).
Try using <%- end -%> instead of <% end %> at the of the form. That
should remove the line feeds and white space.
A lot of rails coders wouldn't use the named scope here.
I always try to keep as much of this sort of logic in the model but
you could also simply use 'find' in the controller:
Sorry to beat the dead horse, but I still need to know how to access
the channel_id given the way I initially posted the code. Can you show
me that? -Janna