Ruby on Rails - adding CSS to text_field -
i created form in rails , when add css class text_field form not submit.
i still new rails appreciated.
this form:
<% @page_title = "contact" %> <hr> <div class="col-lg-12"> <h1 class="page-header"> bk legal courier corp <br />call bk @ <span style="color:#47b224">613-286-8265</span> </h1> </div> <hr> <div class="container"> <h2>contact us</h2> <%= form_for :fc, :url => {:action => 'create'} |f| %> <div class="form-group"> <%= f.label :first_name %> <%= f.text_field (:first_name, :class => 'form-control')%> </div> <div class="form-group"> <%= f.label :last_name %> <%= f.text_field (:last_name, :class => 'form-control') %> </div> <div class="form-group"> <%= f.label :email %> <%= f.text_field (:email, :class => 'form-control') %> </div> <div class="form-group"> <%= f.label :comment %> <%= f.text_area (:comment, :class => 'form-control') %> </div> <div class="form-group"> <%= f.label :referral %> <%= f.select (:referral, [['friends', 1], ['news', 2], ['online', 3], ['other', 4]], :class => 'form-control')%> </div> <%= submit_tag ("submit") %> </form> </div> <% end %> </body> </html>
the problem form submit without :class => "form-control" in it. must have brackets around each of form field variables.
this routes.rb file:
rails.application.routes.draw root "home#index" match ':controller(/:action(/:id))', :via => [:get, :post] end
this controller:
class homecontroller < applicationcontroller def home render("home/index") end def new @fc = feedbackcustomer.new end def create # instantiate new object using form parameters @fc = feedbackcustomer.new(feedbackcustomer_params) if @fc.save redirect_to(:action => "home") end end def application end private def feedbackcustomer_params params.require(:fc).permit(:first_name, :last_name, :email, :comment, :referral) end end
any appreciated. thanks!
if you're using ruby 1.9+ should work:
<%= f.text_field :last_name, class: 'form-control' %>
if you're using version that's older 1.9 should work:
<%= f.text_field :last_name, :class => 'form-control' %>
for more information on can use actionview::helpers::formtaghelper api documentation
the form helpers rails guide might helpful well.
Comments
Post a Comment