【发布时间】:2012-07-27 23:01:22
【问题描述】:
我看到RailsCasts#302 描述了使用 best_in_place gem 进行就地编辑。那里的性别选项 Ryan 使用 show.html.erb 中的数组并将其设为下拉框(请参阅他明确定义数组的性别部分)。
<p>
<b>Gender:</b>
<%= best_in_place @user, :gender, type: :select, collection: [["Male", "Male"], ["Female", "Female"], ["", "Unspecified"]] %>
</p>
但我想要的是我在模型本身内部定义了一个数组,例如:(因为我的数组元素并不简单且数量少)
例如:
user.rb
class User < ActiveRecord::Base
def authencity_types
['Asian', 'Latin-Hispanic', 'Caucasian']
end
end
我将如何使用 best_in_place 语法将此数组元素用作下拉列表。
PS:我确实尝试过这样的事情
<% @users.each do |user| %>
<%= best_in_place user, :authencity, type: :select, :collection => User::authencity_types %>
<% end %>
但它说的是未定义的方法 authencity_types
【问题讨论】:
标签: ruby-on-rails-3 inplace-editing best-in-place