• 简化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
  • 相关阅读:
    php入门到精通(复习笔记)
    MySQL的基础(优化)3
    php之Apache压力测试
    DOS下常用命令
    php连接MySQL分析
    php-memcached详解
    php 四种基本排序算法
    MySQL的基础(优化)2
    SQL入门之集合操作
    SQL入门之多表查询
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/4904403.html
Copyright © 2020-2023  润新知