2015-04-02 75 views
0

嘿,我想這樣做,以便當按鈕被按下時,模式彈出,但模式需要一些來自url參數的數據。例如。即時通訊上:Rails link_to「New Post」,帶參數的「#」?

localhost:3000/posts 

,我按一下按鈕,我需要的URL改成這樣:

localhost:3000/posts?comments_id=14 

我有這個至今:

= link_to "Add Post", '#'(comments_id: @comments.id) 

這顯然不工作,但你可以看到我想要做什麼

回答

3

你可以做到這一點

= link_to "Add Post", posts_path(comments_id: @comments.id) 

= link_to "Add Post", "/posts?comments_id=#{@comments.id}"