Man, as a newbie as soon as I deviate just an inch from the hello
world stuff I'm in all sorts of hurt:)...
I have a controller (lets call it GroceryStoreController) that has an
'add' method (It can be foobar for all I care at the moment, just
something that isn't the conventional ones produced from scaffolding
and that you get mappings to automatically from 'resources' definition
I now have a list of grocery store items and I want to provide an
'add' link next to each item. Hitting the add link should reach the
"add" method in the controller (passing along the id of the grocery
This should be so simple, yet I can't seem to get anything to work. I
don't think I can just use my own xyz_path in link_to since I think
that's just a convention for the built in resources (edit ,etc.) eg:
link_to 'add', add_grocery_store_path(item) #causes undefined path error
I even tried doing things a way that docs say was and older way?:
//sorry pasting from real code I was working with (results after you
do a search)... not grocery_store, but same idea...
@meters.each do |m|
link_to 'add', controller => "meters_search", :action => "add", :id => m
The above creates a link but it looks really bad:
and when you click on it it's trying to find the 'show' method (which
I don't have in this controller, for now just have index, and add
until I get this working) so it breaks.
Maybe it's my Routes that is a problem, and I've been trying different
things there as well. Relevant routes for this example I have as:
get "meters_search/add" => 'meters_search#add'
[ side not for any help in my learning:
I'm also am trying to following the docs for link_to
and it's extremely confusing. It shows some options but then also
mentions see options available by looking at "url_for" so when I click
on that link http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for
I see seven options listed on the page ( anchor, only_path, etc.) yet
they keep showing examples of options like :action, :controller yet I
don't see them shown anywhere in the API as valid options? ]