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
  • 相关阅读:
    C++ map详解
    C++ vector和list的区别
    C++静态存储,动态存储
    C++文件输入和输出
    C/C++数组名与指针的区别详解
    C++运算符重载详解
    poj3177Redundant Paths tarjan缩点
    C++编译过程与内存空间
    [JAVA &#183; 0基础]:19.容器类
    FFmpeg总结(六)AV系列结构体之AVPacket
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/4904403.html
Copyright © 2011-2022 走看看