views:

40

answers:

2

Hello!

I am writing a small application using Rails 3. In one part of it there is a link (should be a link) that if clicked adds a connection between two people (see below).

What I am really needing is to use a normal text link instead of a form, how is this done?

<%= form_for([@profile, @contact]) do |f| %>

    <p><%= f.hidden_field :profile_id, :value => params[:profile_id] %></p>
    <p><%= f.hidden_field :friend_id, :value => profile.id %></p>

    <p><%= f.submit %></p>

<% end %>
+3  A: 

Something like:

<%= link_to 'link these persons', [@profile, @contact], :method => :post, :profile_id => params[:profile_id], :friend_id => profile.id %>
Yannis
I tried it but I get routing errors.
Jonathan Clark
Show us the error please…
Yannis
Ok, this should work: `<%= link_to 'link these persons', profile_contact_path(@profile, @contact, :profile_id => params[:profile_id], :friend_id => profile.id), :method => :post %>
Yannis
Sorry, but this one fails also.
Jonathan Clark
How is it failing? Could you give the html code rendered by this link in your page, and the log of the error you get when you click it?
Yannis
The redered HTML-kod is <a href="/profiles/6/contacts" data-method="post" friend_id="6" profile_id="6" rel="nofollow">Add</a>.
Jonathan Clark
What do you think about this?
Jonathan Clark
What route is the polymorphic_url[@profile, @contact] supposed to render? Is "/profiles/6/contacts" really the url you try to reach via post? if it is the case, try `profile_contacts_path(@profile, :friend_id => profile.id)`.
Yannis
A: 

You can try sumbitting the form with javascript like this:

<%= link_to 'Submit', "#", :onclick=>"('form_id').submit()"%>

This will submit your form.

dombesz