Hey everyone,
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:
…
<%= 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 %>
...Controller:
…
def approve
@post = Post.find(params[:id])
@post.approve!
flash[:notice] = "This post was approved."
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
def disapprove
@post = Post.find(params[:id])
@post.disapprove!
flash[:notice] = "This post was disapproved."
respond_to do |format|
format.html { redirect_to(posts_url) }
format.xml { head :ok }
end
end
…
And in my routes.rb:
…
map.resource :posts, :member => {
:approve => :put,
:disapprove => :put
}
…