替换index和show中select_tag的方法

channel_type对应多种类型,每个类型在数据库中存储的字段和在页面上显示的字段是不同的,

如果在index里直接使用 select_tag 方法,是这样的:

<%= select_tag "channel_type", options_for_select([['信号源', 'signal_source'],
['直播轮播', 'live_and_rotate'],
['我的','my_channel'],
['cibn频道','cibn_channel']],@launcher_channel.channel_type) %>

不过这个下拉菜单显得有些多余,

可以在model里加一个方法,

  def channel_type_human
    {   
      signal_source:  '信号源',
      live_and_rotate:  '直播轮播',
      my_channel:  '我的',
      cibn_channel:  'cibn频道'
    }[channel_type.to_sym]
  end 


再 view 中,直接调用 channel.channel_type_human 就可以啦 

posted @ 2015-10-22 15:49  冰凌花花~  阅读(191)  评论(0编辑  收藏  举报