Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Ruby on Rails 4: options value in form_for and fields_for helper

rails4 helper form_for fields_for

  • Please log in to reply
No replies to this topic

#1 Diesel

Diesel

    Passenger

  • Members
  • 2 posts

Posted 06 August 2014 - 04:15 AM

I want to make a helper for the bootstrap, and for controls (text_field, label ...) I need to use the options of the form_for. There is a form

<%= form_for(@user, url: signup_path, layout: :horizontal) do |user_f| %>
  <%= user_f.fields_for :person do |person_f| %>
    <%= person_f.text_field(:last_name) %>
      <%= person_f.options %>
    <% end %>
    <%= user_f.text_field(:last_name) %>
    <%= user_f.options %>
<% end %>

I need to get the value :layout in the control from the form_for I do not understand why <%= user_f.options %> displays:

{:url=>"/signup?locale=ru", :layout=>:horizontal, :html=>{:class=>"new_user", :id=>"new_user", :method=>:post, :authenticity_token=>nil}}

And <%= person_f.options %> displays:

{:builder=>nil, :namespace=>nil, :parent_builder=>#<ActionView::Helpers::FormBuilder:0x007fd338058c60 @nested_child_index={}, @options={:url=>"/signup?locale=ru", :layout=>:horizontal, :html=>{:class=>"new_user", :id=>"new_user", :method=>:post, :authenticity_token=>nil}}, @template=#<#<Class:0x007fd338030738>:0x007fd3375e2268 @_routes=nil, @_config={}, @view_renderer=#<ActionView::Renderer:0x007fd3375e2510 @lookup_context=#<ActionView::LookupContext:0x007fd3375d31a0 @details_key=#<ActionView::LookupContext::DetailsKey:0x007fd3371da5f8 @hash=-3796700121417373084>, @details={:locale=>[:ru], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}, @skip_default_locale=false, @cache=true, @prefixes=["signup", "application"], @rendered_format=:html, @view_paths=#<ActionView::PathSet:0x007fd3375d3970 @paths=[#<ActionView::OptimizedFileSystemResolver:0x007fd33720f3e8 @pattern=":prefix/:action{.:locale,}{.:formats,}{.:handlers,}", @cache=#<ActionView::Resolver::Cache:0x007fd33720f3c0 @data=#<ActionView::Resolver::Cache::SmallCache:0x007fd33720f398 @backend={#<ActionView::LookupContext::DetailsKey:0x007fd3371da5f8 @hash=-3796700121417373084>=>#<ActionView::Resolver::Cache::SmallCache:0x007fd3371d9810 @backend={"new"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd3371d96d0 @backend={"signup"=>#<ActionView::Resolver::Cache::SmallCache:0x007fd3371d9540 @backend={false=>#<ActionView::Resolver::Cache::SmallCache:0x007fd3371d9450 @backend={[]=>[app/views/signup/new.html.erb]}, @default_proc=nil>}, @default_proc=#<Proc:0x007fd33438afe0@/Users/NikolayLipovtsev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_view/template/resolver.rb:45 (lambda)>>}, @default_proc=#<Proc:0x007fd33438afb8@/Users/NikolayLipovtsev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_view/template/resolver.rb:46 (lambda)>>, 

...and there is more still large hash. As well that the form options contains much information?

How I can get :layout from person_f.text_field and user_f.text_field?

 

 

 

 







Also tagged with one or more of these keywords: rails4, helper, form_for, fields_for

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users