开发者

ROR link_to parameters

开发者 https://www.devze.com 2023-03-24 15:10 出处:网络
in routes.rb I have such a line resources :ideas and in a view I have: <%= link_to \'My ideas\',ideas_path+\'?id=my\' %>

in routes.rb I have such a line

resources :ideas

and in a view I have:

<%= link_to 'My ideas',ideas_path+'?id=my' %>
<%= link_to 'My ideas',ideas_path, :id=>'my' %>

first line opens: http://localhost:2000开发者_开发百科/ideas?id=my while the second opens: http://localhost:2000/ideas

How to fix the second line? Bye


<%= link_to 'My ideas',ideas_path(:id=>'my') %>


Rails paths sort out your paramaters for you.

To link to a single 'idea' you could do something like ...

<%= link_to 'One idea',idea_path(@idea) %>

To link to all your 'ideas' then

<%= link_to 'All ideas',ideas_path %>
0

精彩评论

暂无评论...
验证码 换一张
取 消