This is my first post to the forums. I'm trying to add an 'approve' and
'disapprove' link for new content to my website. I thought I should
just add two links to the "show" view to trigger the "approve" and
"disapprove" method. Clicking these links doesn't have any effect in
the DB. Is this the totally wrong approach or is my syntax just bad?
I've included the code below.
View:
...
<p class="right">
<%= link_to 'Approve', post, :action => 'approve', :id => post %> |
<%= link_to 'Disapprove', post, :action => 'disapprove', :id => post %>
<p class="right">
<%= link_to 'Approve', post, :action => 'approve', :id => post %> |
<%= link_to 'Disapprove', post, :action => 'disapprove', :id => post %>
>
<%= link_to 'Edit', edit_post_path(post) %> |
<%= link_to 'Delete', post, :confirm => 'Are you sure?', :method =>
:delete %>
</p>
A couple of things:
1) Your resource is configured to only accept put method type and your
links appear to be get.
2) In the link_to its self I would use:
<%= link_to 'Disapprove', disapprove_post_path(post), :method => 'put'
%>
Notice that I added the method and am now using the route helpers?
There is more to talk about the approach, but you'll get it working with
those two changes.
This is my first post to the forums. I'm trying to add an 'approve' and
'disapprove' link for new content to my website. I thought I should
just add two links to the "show" view to trigger the "approve" and
"disapprove" method. Clicking these links doesn't have any effect in
the DB. Is this the totally wrong approach or is my syntax just bad?
I've included the code below.
View:
...
<p class="right">
<%= link_to 'Approve', post, :action => 'approve', :id => post %> |
<%= link_to 'Disapprove', post, :action => 'disapprove', :id => post %>
>
<%= link_to 'Edit', edit_post_path(post) %> |
<%= link_to 'Delete', post, :confirm => 'Are you sure?', :method =>
:delete %>
</p>
...