Ruby on Rails - possible unmatched constraints: [:id]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Ruby on Rails - possible unmatched constraints: [:id]



I'm releasing a RoR app running on Heroku and I've been adding all my customers. Everything was ok but there are a few customers that I just can't add because it throws me a 500 error saying: "ActionView::Template::Error (No route matches :action=>"edit", :controller=>"account_activations", :email=>"customer@customer.com", :id=>nil, possible unmatched constraints: [:id]):" and I was able to add almost all of them.
What is happening?



Here's my creating clients controller:


def create
@client = Client.new(client_params)
if @client.save
newUser = @client.create_user(name: @client.name,
email: @client.email,
password: "PASSWORD",
password_confirmation: "PASSWORD",
role: "client")
newUser.send_activation_email
redirect_to root_url
else
render 'new'
end
end





put your full error trace from the log
– praga2050
59 mins ago






Looks like one of the validations on your User model is failing and so the user isn't being saved. What are the validations on User?
– mikej
56 mins ago



User


User





@mikej That's what I am realizing... The name validation for the user has a minor length than the customer. Let me see if changing that works.
– Aldo
50 mins ago





..., :id=>nil , the question is how are you making the request to load that template.
– Sebastian Palma
38 mins ago


..., :id=>nil





@Aldo Where does the error originate from? Post the full error, not just the last line. And why isn't the client saving? Again, post the full information -- in this case, the Client model and the client_params.
– Tom Lord
36 mins ago


Client


client_params




1 Answer
1



Found the error. With my client validations I had a name length of 255 while in my user validations I had a length of 50. Some of my customers have names greater than 50 characters. In my controller I just verified with an if statement if client was saved but not the user. The user was failling to be created as @mikej said so I changed the user name validation length also to 255 and now it works.
Thanks!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Mass disable jenkins jobs