Question

I just watched http://railscasts.com/episodes/184-formtastic-part-1 and after implementing my code, the form and everything else worked perfectly, except that when i create the form and go to the show page, it will add an integer instead of the chosen name

So for example in the form if i put

Category: Feline

on the show page it would put

Category: 1

If i put

Category: Example

on the show page it would put

Category: 2

Does anyone know why it shows this and how i could make it show the name i chose

Thanks!

Was it helpful?

Solution

It is incomplete. Check the code (he always upload the code to Github) https://github.com/railscasts/184-formtastic-part-1/blob/master/vet/app/views/animals/show.html.erb

So, instead of:

<p>
  <strong>Category:</strong>
  <%=h @animal.category_id %>
</p>

Put:

<p>
  <strong>Category:</strong>
  <%=h @animal.category.name %>
</p>

Use the association of ActiveRecord

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top