【发布时间】:2012-11-27 16:29:14
【问题描述】:
我的 Rails 应用程序目前使用 collection_select 来选择下拉列表等的查找值。这有两个优点:
- 数值一致
- 数据库中存储的是选中值的id,而不是文本值
例如: 编辑.html.erb
<div class="field">
<%= f.label :course_type %><br />
<%= f.collection_select :course_type, Lookup.find(:all,:conditions => ["model_name = 'course' and field_name = 'course_type'"]), :id, :lookup_text, include_blank: false,:prompt => "Course Type" %>
</div>
course_controller.rb
private
def get_lookups
@course = Course.find(params[:id])
@course_type = Lookup.find(@course.course_type).lookup_text
show.html.erb
<b>Course type:</b>
<%= @course_type %>
我的应用程序将是多语言的,Rails 使用语言环境文件来处理这个问题。
问题是:是否可以(并且明智)从 yml 文件而不是模型/表中填充查找值,并且可以轻松扩展以处理多种语言吗?上面的代码怎么能换成基于yml的代码呢?
【问题讨论】:
标签: ruby-on-rails internationalization yaml