Adding Twitter bootstrap styling to Rails form helpers

后端 未结 2 659
时光取名叫无心
时光取名叫无心 2021-02-10 17:20

After reading the answer which suggested I use Simple_form gem with bootstrap integration, I installed it and created my form according to simple_form instructions, but the inpu

2条回答
  •  盖世英雄少女心
    2021-02-10 18:16

    You should try the following:

    <%= form_for("user", :url => main_app.user_registration_path, :html => { :class => "form-horizontal" } ) do |f| %>
    
    User Registration
    <%= f.label :name, class: "control-label" %>
    <%= f.text_field :name %>

    <%= f.submit %>

    Note that the bootstrap uses some specific selectors for some classes / html elements, so that if you forget to add an element or a class, everything else will be messed up... In this aspect there's no leeway.

    On a side note, you should definitely try simple_form, and the bootstrap integration. It will make your life easier.

    Update:

    <%= simple_form_for("user", :url => main_app.user_registration_path, :html => { :class => "form-horizontal" } ) do |f| %>
    
    User Registration <%= f.input :name %> <%= f.input :vote, :collection => [ "For", "Against", "Undecided"] %> <%= f.input :country, :collection => [ "Canada", "Iceland", "Other"] %> <%= f.input :email %> <%= f.input :image, :as => :file %> <%= f.input :password %> <%= f.input :password_confirmation %>
    <%= f.submit %>
    <% end %>

提交回复
热议问题