rugbert
rugbert

Reputation: 12653

update record with custom action and link_to

Im trying to update a single attribute on a record from a text link but I cant seem to make it work.

here is my controller action:

  def approve
    @tattoo = Tattoo.find(params[:id])
    @tattoo.upate(:status => "approved")
      respond_to do |format|
        format.js
      end
  end

my link to is:

<%= link_to "Approve", approve_admin_tattoos_path(tattoo), :remote =>true, :method => :put %>

and my route is:

match "/admin/approve/:id" => "admin#approve", :as =>"approve_admin_tattoos", :via => :post

But I keep getting this error:

Started PUT "/admin/approve/223" for 127.0.0.1 at 2012-01-07 12:57:29 -0500
  Processing by ErrorsController#not_found as JS
  Parameters: {"id"=>"223"}
Rendered shared/_login.html.erb (192.1ms)
  Member Load (0.2ms)  SELECT `members`.* FROM `members` WHERE `members`.`id` = 7 LIMIT 1
  MemberRole Load (0.1ms)  SELECT `member_roles`.* FROM `member_roles` WHERE (`member_roles`.member_id = 7) LIMIT 1
  SQL (0.7ms)  SHOW TABLES
  SQL (0.1ms)  SELECT COUNT(*) FROM `tattoos` WHERE `tattoos`.`status` = 'pending'
      SQL (0.1ms)  SELECT COUNT(*) FROM `feedbacks` WHERE `feedbacks`.`approved` = 0
  SQL (0.1ms)  SELECT COUNT(*) FROM `tattoos` WHERE `tattoos`.`status` = 'reported'
Rendered shared/_navbar.html.erb (701.3ms)
Rendered shared/_login_form.html.erb (2.6ms)
Rendered errors/not_found.html.erb within layouts/application (912.7ms)
Completed 404 Not Found in 929ms (Views: 925.8ms | ActiveRecord: 1.4ms)

ActionController::RoutingError (uninitialized constant AdminController):

Upvotes: 0

Views: 652

Answers (1)

Wahaj Ali
Wahaj Ali

Reputation: 4103

I think this is something to do with routes. In your routes you have :via => :post, but in the view you have :method => :post. If you are updating, than according to the REST you should have put. You could also declare your routes as:

put "approve" => "admin#approve", :as =>"approve_admin_tattoos"

Also, I think the first slash in 'match "/admin/approve/:id"' could also be a cause for break.

Upvotes: 1

Related Questions