0

I'm trying to pass a string from a variable in my Rails app to the database. It's the user's email address. I cannot for the life of me figure out why I'm getting an "undefined method `merge'" error.

Here's the offending code:

<%= f.email_field :commenter, current_user.email %>

Any help will surely help. Cheers!

1 Answer 1

1

Rails expect the second argument to be a hash, so you'd want to do

<%= f.email_field :commenter, value: current_user.email %>

Or better yet, set the :commenter attribute in that particular model in the controller (after you initalize/build it), then you can leave out this value hax. That way, when use edit this, post the form, and get a validation error, the value will be what's user were posting, not current_user.email.

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.