zoukankan      html  css  js  c++  java
  • 简化select_tag/form

    在model里新建

      CHANNEL_TYPES = { 
        '信号源': :signal_source,
        '直播轮播': :live_and_rotate,
        '我的': :my_channel,
        'C 频道': :c_channel
      }

    并增加方法

      def channel_type_human
        CHANNEL_TYPES.invert[channel_type.to_sym]
      end 

    在view/form里可以直接用

          <div class="form-group">
            <%= f.label :channel_type,"频道类型", class: "col-sm-2 control-label" %>
            <div class="col-sm-2">
              <%= f.select :channel_type, options_for_select(LauncherChannel::CHANNEL_TYPES, @launcher_channel.channel_type),
                {}, class: "form-control" %>
            </div>
          </div>

    之前没有加{}, 由于默认是四个参数的,最后一个才是html_option

    select(method, choices = nil, options = {}, html_options = {}, &block)
    
    Wraps ActionView::Helpers::FormOptionsHelper#select for form builders:
    
    <%= form_for @post do |f| %>
      <%= f.select :person_id, Person.all.collect { |p| [ p.name, p.id ] }, include_blank: true %>
      <%= f.submit %>
    <% end %>
    Please refer to the documentation of the base helper for details.
    
    Source: hide | on GitHub
    
    # File actionview/lib/action_view/helpers/form_options_helper.rb, line 776
    def select(method, choices = nil, options = {}, html_options = {}, &block)
      @template.select(@object_name, method, choices, objectify_options(options), @default_options.merge(html_options), &block)
    end
  • 相关阅读:
    OI中的小智慧
    洛谷 P2335 SDOI 2005 毒瘤 位图(也补上注释了)
    洛谷P4779 Dijkstra 模板
    洛谷 P1156 垃圾陷阱 谈论剪枝,非满分
    8/14考试 JWG
    一个好消息 JWG
    刷水题(一) JWG
    C语言运算符优先级从没像现在这样深刻体会
    cron 备忘
    CentOS
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/4904403.html
Copyright © 2011-2022 走看看