0

My application is using Rails 4 with inherited_resources. Very oddly, the update action does not appear to work. When try to submit the form on the edit page, I get this error:

ArgumentError in Admin::FaqsController#update
wrong number of arguments (6 for 1)

There are 6 fields in the form. My controller is like this:

class Admin::FaqsController < Admin::AdminController
  inherit_resources
  respond_to :html
  actions :index, :new, :create, :edit, :update, :destroy

  private

  def resource_params
    params.require(:faq).permit(:title, :slug, :body, :publish_immediately, :published_at, :status)
  end
end

Why is this happening? Is it an incompatiblity with Rails 4, and I just need to do the update action myself?

Charles
  • 50,943
  • 13
  • 104
  • 142
Jonah
  • 9,991
  • 5
  • 45
  • 79
  • 1
    Are you sure your Faq form is well formatted? What happens if you replace `params.require(:faq).permit(:title, :slug, :body, :publish_immediately, :published_at, :status)` with `params.require(:faq).permit!`? – Raindal Sep 04 '13 at 19:48
  • Same thing. I double-checked the request data too, and the correct fields are present. That error is clearly coming from somewhere in the gem, unfortunately it doesn't give me a full stack trace. If it did, I might be able to figure out what the problem is. Is there a way to make it show the full stack track? – Jonah Sep 04 '13 at 20:22

1 Answers1

2

Seems I figured it out. I went back through the documentation and saw that I was using the params permit incorrectly. I thought it was called resource_params with a require call, but it is as follows:

class Admin::FaqsController < Admin::AdminController
  inherit_resources
  respond_to :html
  actions :index, :new, :create, :edit, :update, :destroy

  private

  def permitted_params
    params.permit(faq: [:title, :slug, :body, :publish_immediately, :published_at, :status])
  end
end

The difference is in calling the method permitted_params, and returning the entire params array with specific fields within it permitted, instead if only the resource's fields.

Jonah
  • 9,991
  • 5
  • 45
  • 79