Ruby on Rails - possible unmatched constraints: [:id]
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKPz5qhCkKGdpPJ0wkSm5JqlliSJoZg92-H4DuCruovhkVFuXerCphZt9wys_Gr3uwQyXObMHDwattjG5BSeCEl_LdDq1GPLct8qYyRyX4fZ9C93oW-TX7IGZLYDwqRgfFCXA4aUxkBAcS/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6VebLk98DYwS3K2nWZSCatab-q4HrSuRk91M4fQA8SHrKU_-x-lq1n780pSU_bIVLqMRv6pc3dhhh-Y2PUwBS9mM0BxvY1eM6XsM-e7Diu4z-wAoeDG0vB3-2_1U9RE8sO0lg4PHiIXbI/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
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
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.
put your full error trace from the log
– praga2050
59 mins ago