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
}
...
--
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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
> Hey everyone,Hey David,> <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. Paul> And in my routes.rb: > > ... > map.resource :posts, :member => { > :approve => :put, > :disapprove => :put > } > ...-- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sent from my iPhone On Mar 16, 2010, at 8:00 PM, David Raffauf <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > 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. -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.