Reputation: 411
i'm struggling to understand why this is happen with destroy method since everything on controller and routes is ok!
if someone passed through this way please could give me a hint?
Routes
resources :users, :as => "" do
resources :sections, :only => [:new, :create, :destroy, :index]
end
Controller
def destroy
@section = Section.find(params[:id])
@section.destroy
redirect_to sections_url
flash[:notice] = "Section deleted"
end
View
<%= render :partial => "section", :collection => @sections %>
Partial
<%= link_to section.name, section_path(current_user, section) %>
<%= button_to 'Remove', current_user, section, :data => { :confirm => 'Confirm?' }, :class=> "buttom", method: :delete %>
Upvotes: 0
Views: 3984
Reputation: 411
codeit, Stefan did what you guys said but did not work, so i tried the path instead and worked!
<%= button_to 'Remove', section_path(current_user, section), :data => { :confirm => 'Confirm?' }, :class=> "button", method: :delete %>
Upvotes: 0
Reputation: 114228
The problem seems to be this method call:
button_to 'Remove', current_user, section, :data => { :confirm => 'Confirm?' }, :class=> "buttom", method: :delete
The pair current_user
and section
has to been passed as an array:
button_to 'Remove', [current_user, section], confirm: 'Confirm?', class: "buttom", method: :delete
Upvotes: 2
Reputation: 10137
Your button_to
helper arguments are wrong.
Try this:
<%= button_to 'Remove', {:action => :destroy, :user => current_user, :id => section}, {:data => { :confirm => 'Confirm?' }, :class=> "buttom", method: :delete} %>
Upvotes: 1
Reputation: 8621
That error means that some function takes 1 to 3 arguments, but you gave to it 4 arguments.
Please see the row number in the error and look up the function, then open documentation and look up how to use that function. Often functions works differently as instance methods and class methods.
Upvotes: 2