How to use the Rails helper link_to RESTfully in this situation?

Basically I want to use link_to to reference the controller index method. I tried:

<%= link_to 'Recipes', Recipe %> 

but outputs:

<a href="/recipes/Recipe">Recipes</a>

Which is clearly wrong, if he left this last bit, it would do exactly what I want. I thought that with RESTful I would somehow start to miss an action or something like that. What? I do not understand?

+3
source share
1 answer

With the rest of the routes, most of the time you expect to call a helper method to generate the route.

eg:

link_to 'Recipes', recipes_path

There is an optimization where you can simply pass the recipe object and it will call an auxiliary method for you behind the scenes: for example:

link_to 'Recipe X', @recipe

coincides with

link_to 'Recipe X', recipe_path(@recipe)

However, this is just a special case.

, , , . , , , .to_s , , recipe_path, URL-.

. _path, _url.

_url URL-, http://stackoverflow.com/recipes/5, _path /recipes/5.
URL- , , rails mongrel, , , 1.2.3.4 (, IP- ) URL-, .

+6
source

Source: https://habr.com/ru/post/1698016/


All Articles