1

I have this:

      <li><%= link_to "More", feed_products_path(product.id) ,{:class=>"button-small white"} %></li>

This link outputs: http://localhost:3000/feed_products.34

I would like to see if as: http://localhost:3000/feed_products/34

How do I do this in Ruby on Rails?

Thanks!

2
  • can you post your routes file too. Commented Feb 6, 2012 at 4:26
  • I just did resources :feed_products Commented Feb 6, 2012 at 4:28

1 Answer 1

1

Replace the path in above link to with

 feed_product_path(product)

feed_products_path is for the index action. If you pass an object to it then it appears as format("format" => "1"), 1 being the id of the object passed, in the params hash.

I hope you are not trying to pass an object there. Let me know if this helps.

Sign up to request clarification or add additional context in comments.

5 Comments

may be feed_product_path(@product) depending on controller.
yea, may be :) but the OP is successfully accessing it as a local and not an instance variable.
Yeah this works. Thanks. I do have some follow up questions: Why did you say this? "I hope you are not trying to pass an object there. Let me know if this helps." and whats the difference between passing product and @product Ruby / Ruby on Rails Newbie.
feed_products_path is routed to index action of FeedProducts controller. Generally, all corresponding objects are accessed in an index action. So, it does not make sense passing a specific object(of the same class) to an index action. Lets consider a show action feed_product_path(product), which requires an object to be passed, i.e. specify which specific object is to be shown.
'@product' is an instance variable. If you define it in an action, you can access it in the corresponding view(and otherwise for a local variable). Say '@products' in index action and '@products.each do |product|' in your view. S0, '@products' in the instance variable and in your view 'product' is a local variable. Its scope is only in that view, i.e. you need to pass it to a partial or a helper. Finally, (woosh) with "Let me know if this helps", I was just trying to be polite and helpful :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.