Sent from my iPhone

On Mar 16, 2010, at 8:00 PM, David Raffauf <li...@ruby-forum.com> wrote:

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:

...
<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>
...

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
 }

Dave, can you post your model file?

Thanks,

-Conrad

...
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to