1

I have a definition

def create
   @person = Person.new(params.require(:firstname, :lastname, :job).permit(loc))
   @person.save
   redirect_to @person

When I try to save a new person I get the following error:

ArgumentError in PeopleController#create
wrong number of arguments (5 for 1)

Is there an issue with the way I coded it? I also tried separating out each element with a separate ".require".

4
  • I think the problem is around params.require(:firstname, :lastname, :job).permit(loc) can you post params and what fields you want to save for person? Commented May 1, 2015 at 16:24
  • 2
    The error wrong number of arguments (5 for 1) would suggest that you are passing 5 arguments to a method, but you aren't anywhere in the code you posted. So, the bug is probably somewhere else in your code. Commented May 1, 2015 at 16:31
  • 1
    In response to Adrian's comment you might want to post your Person model initialize as well as any before_ or after_ initialize Commented May 1, 2015 at 16:40
  • 1
    @Joe's answer below is correct. Parameters your controller is receiving from the view are in the form of a hash called Person. You want to require person and permit all of the other variables. As far as validating that the values passed aren't nil, you can do this in the Model instead of marking :first_name, :last_name, and :job as "required." Commented May 1, 2015 at 17:42

1 Answer 1

2

Typically you want something like params.require(:person).permit(:firstname, :lastname, :job, :loc) then have your Person model validate the required attributes.

As for your issue, my guess is if you check your params you will see something like {person: {firstname: "first", lastname: "last", job: 1, loc: "somewhere"}} coming through and that is why your Person.new is raising that error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.