开发者

Pass url arguments with link_to?

开发者 https://www.devze.com 2023-03-14 08:25 出处:网络
Rails 2.3.11 I didn\'t see anything i开发者_开发技巧n the Rails UrlHelper API about this, but I\'m sure it\'s trivial (I\'m still learning Rails).

Rails 2.3.11

I didn't see anything i开发者_开发技巧n the Rails UrlHelper API about this, but I'm sure it's trivial (I'm still learning Rails).

I need to generate a URL using link_to with arguments added:

http://.../posters/new?event_id=53 rather than http://.../posters/new

Thank you!


link_to('link text', new_poster_url(:event_id => event.id))

You could also take a look at nested resources for alternative URL mapping.


It depends if you use named routes or use a hash of options, but both are straightforward.

<%= link_to @post.title, {:controller => 'posts', :action => "show", :some_param => "some params"} %>

And if you have named_rotes which are coming from map.resources or whatever you can do it this way:

<%= link_to @post.title, post_path(:some_param => 'some param') %>

Then you can access these params in your controller:

def show
   some_param = params[:some_params]
end
0

精彩评论

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