0

I have a view that uses link_to to pass parameters to a controller. The url is a variable. Something is not working. I'd appreciate any clues. Thanks!

<% url1 = dialogs_path(@dialogId) %>
<%= url1 %>
<%= link_to "Go!", url1(:uid1 => @uid1, :uid2 => @uid2), :id => "my_link" %>

url1 displays correctly. However, executing link_to crashes.

user1388066
  • 97
  • 2
  • 9
  • What does "crashes" mean? Seeing a stack trace or error message of some sort would help. – BaronVonBraun Aug 09 '12 at 01:49
  • Thanks @BaronVonBraun! I'm working on it. When the page that includes the link_to statement is rendered I get "we are sorry, but something went wrong". – user1388066 Aug 09 '12 at 02:29

2 Answers2

0

You should use dialog_path(@dialogId) instead.

You're trying to view a particular object, it's singular and what rails expects. Take a look here : http://guides.rubyonrails.org/routing.html#paths-and-urls

The way you use url confuses me, try something like this :

<%= link_to "Go!", dialog_path(@dialogId, :uid1 => @uid1, :uid2 => @uid2), :id => "my_link" %>
Anthony Alberto
  • 10,325
  • 3
  • 34
  • 38
0

The url1 should be defined as:

<% url1 = dialogs_path(@dialogId)+'?uid1=' + @uid1 + '&uid2=' + @uid2% , :id => "my_link" %>

And the link_to should be:

<%= link_to "Go!", url1, :id => "my_link" %>
Anthony Alberto
  • 10,325
  • 3
  • 34
  • 38
user1388066
  • 97
  • 2
  • 9