samedi 28 février 2015

How to display data from one single column into multiple inputs?

I work on an application and I have a model with a 'movies' attribute (top 5 movies). When a user tries to edit the top 5 movies I want to display each movie in a different input, but I don't know how to do it (because all 5 movies represent one single attribute)


In my controller



def show
@user = User.find(params[:id])
@user.movies = @user.movies.split(',')
end


In my model



<%= form_for @user do |f| %>
<%= f.label :movies %>
<%= f.text_field :movies[0] %>
.
.
.
<%= f.label :movies %>
<%= f.text_field :movies[4] %>
<% end %>


Of course, this doesn't work!


Aucun commentaire:

Enregistrer un commentaire