module ActionView::Helpers::AutoTagHelper::FormInfo
Public Class Methods
display_options(column_name)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 13 def display_options(column_name) (@display_options ||= {})[column_name.to_sym] end
editable_columns()
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 21 def editable_columns @editable_columns end
input_options(column_name)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 17 def input_options(column_name) (@input_options ||= {})[column_name.to_sym] end
select_list(column_name)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 25 def select_list(column_name) list = (@select_list ||= {})[column_name.to_sym] list = list.call if list && list.kind_of?(Proc) if !list && self.respond_to?(:reflections) relation = self.reflections[column_name.to_s.gsub(/_id$/,'')] model = relation.klass if relation list = model.all.to_a if model end list end
showable_methods()
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 9 def showable_methods @showable_methods end
Protected Class Methods
clear_editable_methods()
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 49 def clear_editable_methods @editable_columns = nil end
clear_showable_methods()
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 64 def clear_showable_methods @showable_methods = nil end
set_accessible_attrs(*args)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 37 def set_accessible_attrs(*args) set_showable_methods(*args) set_editable_columns(*args) end
set_display_options(column_name,options)
click to toggle source
Starts a form tag that points the action to an url configured with url_for_options
just like ActionController::Base#url_for. The method for the form defaults to POST.
Parameters:¶ ↑
- column_name
-
Target column name
Options¶ ↑
-
:method
- called method name -
:type
- display type -
Any other key creates standard HTML attributes for the tag.
Examples¶ ↑
class User < ActiveRecord::Base include ActionView::Helpers::AutoTagHelper::FormInfo set_display_options('my_photo_url',method: :image_tag, args: ->(v,rec){ [v,{ width: 64px, height: 64px }] }) set_display_options('myhome_latlot',type: :latlot} def myhome_latlot {lat: self.my_home_lat, lot: self.my_home_lot} end end module LatLon def self.display_tag latlon,html_options lat = latlon[:lat] lon = latlon[:lon] "<div>lat: #{lat}, lon: #{lon}</div>" end end ActionView::Helpers::AutoTagHelper::DisplayTypes.register(:latlon, LatLon) user = User.find(1) puts user # => #<User id: 1, email: "myemail@gmail.com", my_photo_url: "https://mywebsite.com/user/1/photo.jpg", my_home_lot: 139.691706, my_home_lat: 35.689487> display_tag(:my_photo_url, user) # => image_tag("https://mywebsite.com/user/1/photo.jpg", {width: '64px', height: '64px'}) display_tag(:my_photo_url, user, width: '128px', height: '128px') # => image_tag("https://mywebsite.com/user/1/photo.jpg", {width: '128px', height: '128px'}) display_tag('myhome_latlot', user) # => <div>lat: 35.689487, lon: 139.691706</div>
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 109 def set_display_options(column_name,options) (@display_options ||= {})[column_name.to_sym] = options end
set_editable_columns(*args)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 42 def set_editable_columns(*args) if args.present? ( @editable_columns ||= [] ).concat(args.map(&:to_sym)).uniq! end @editable_columns end
set_input_options(column_name,options)
click to toggle source
Examples¶ ↑
set_input_options :hoge_crypted_password, type: :password, maxlength: 8 set_input_options :hoge_percent, type: :range, min: 0, max: 100
Enable combinations of column’s type and input type¶ ↑
-
datetime
- :datetime_local -
string
- :color, :email, :number, :password, :phone, :telephone, :url -
integer
- :range, :week, :month
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 121 def set_input_options(column_name,options) (@input_options ||= {})[column_name.to_sym] = options end
set_select_list(column,list=nil,&block)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 53 def set_select_list(column,list=nil,&block) (@select_list ||= {})[column.to_sym] = (block || list) end
set_showable_methods(*args)
click to toggle source
# File lib/action_view/helpers/auto_tag_helper/form_info.rb, line 57 def set_showable_methods(*args) if args.present? ( @showable_methods ||= [] ).concat(args.map(&:to_sym)).uniq! end @showable_methods end