开发者

looping through multiple attributes in rails

I am using has_many: skills in my user model and I'm wondering, after a user has selected many skills in dynamically generated form fileds, how do I pull all the skills into an array and di开发者_高级运维splay them into my view?


I think this is what you want to do... if not, please update your question with what output you're really looking for. Like @thefugal, I'm assuming skill has a name.

Since @user.skills is an array, you need to loop over each of them.

<ul>
  <% @user.skills.each do |skill| %>
    <li><%= skill.name %></li>
  <% end %>
</ul>


Have the skills been persisted yet? If so, with that association, you should be able to get an array of a user's skills (assuming you have a user @user) with

@user.skills
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜