# Add a method for approving/disapproving content

**URL:** <https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266>\
**Category:** Rails\
**Created:** [March 17, 2010, 4:00am UTC](https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266 "2010-03-17T04:00:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [March 17, 2010, 4:00am UTC](https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266/1 "2010-03-17T04:00:18Z")

</div>

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  
}  
…

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [March 17, 2010, 7:04am UTC](https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266/2 "2010-03-17T07:04:30Z")

</div>

> Hey everyone,  
> Hey David,

> \<%= 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 %\>

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.

Paul

> And in my routes.rb:
> 
> …  
> map.resource :posts, :member =\> {  
> :approve =\> :put,  
> :disapprove =\> :put  
> }  
> …

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [March 17, 2010, 7:43am UTC](https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266/3 "2010-03-17T07:43:46Z")

</div>

> Dave, can you post your model file?

Thanks Conrad. I found a workaround and got some pointers on how to  
build the links. I’ll report back on the link approach tomorrow.

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [March 17, 2010, 7:18am UTC](https://www.ruby-forum.com/t/add-a-method-for-approving-disapproving-content/185266/4 "2010-03-17T07:18:21Z")

</div>

Sent from my iPhone

On Mar 16, 2010, at 8:00 PM, David R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> :delete %\>  
> flash[:notice] = “This post was approved.”  
> @post.disapprove!
> 
> And in my routes.rb:
> 
> …  
> map.resource :posts, :member =\> {  
> :approve =\> :put,  
> :disapprove =\> :put  
> }

Dave, can you post your model file?

Thanks,

-Conrad
