Sha256: fe506f3c55ffc3a0c69bb01fc7816ecf7edb241f0f2e13e1bedf5a5179687bca
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module ExpressTemplates module Components module Forms class ExpressForm < Base include Capabilities::Configurable include Capabilities::Parenting emits -> { form( form_args ) { form_rails_support form_method _yield } } def form_id "#{resource_name}_{{@#{resource_var}.id}}" end def form_method @config[:method] end def form_action if _modifying_resource? "{{#{resource_name_for_path}_path(@#{resource_name})}}" else # posting a new to a collection # We also have to take in to account singular resources # e.g. resource :config -> will throw an unknown method error of configs_path "{{#{resource_name_for_path.pluralize}_path}}" end end def form_args # there are no put/patch emthods in HTML5, so we have to enforce post # need to find a better way to do this: id/action can be overridden but method # should always be :post IN THE FORM TAG args = {id: form_id, action: form_action}.merge!(@config).merge!(method: :post) if html_options = args.delete(:html_options) args.merge!(html_options) end args[:method] = args[:method].to_s.upcase args end def resource_name_for_path @config[:id].to_s end def resource_name (@config[:resource_name] || @config[:id]).to_s end def namespace @config[:namespace] end private def _modifying_resource? [:put, :patch].include? form_method end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
express_templates-0.4.1 | lib/express_templates/components/forms/express_form.rb |