-3

I am new in RoR. I am trying to add css classes on my form. Here is my form:

<%= form_tag :action => 'create' do %>
  <p><label for = "name">Name</label>:
    <%= text_field 'books', 'name' %></p>
  <div class="form-control">
  <p><label for = "author">Author</label>:
    <%= text_field 'books', 'author'%></p>
  </div>
  <p><label for = "price">Price</label><br/>
    <%= text_area 'books', 'price'%></p>
  <%= submit_tag "Create" %>
<% end -%>

That form controls does not accepting class="form-control mb-4 col-10" placeholder="Patient name" like <input type="text" th:field="*{name}" class="form-control mb-4 col-10" placeholder="Patient name">. How can I apply css styling.

fidato
  • 719
  • 5
  • 22
Muzammal Hussain
  • 121
  • 1
  • 11
  • What do you mean by 'no accepting?' Have you tried defining the css in `app/assets/stylesheets/*somefile*.css` and referencing the file in `app/assets/stylesheets/application.css` through ` *= require *somefile*.css ` Are you attempting to set the class? – benjessop Aug 13 '20 at 07:05
  • 2
    Does this answer your question? [Setting the class of HTML elements using Rails?](https://stackoverflow.com/questions/11572514/setting-the-class-of-html-elements-using-rails) – AndrewL64 Aug 13 '20 at 07:05
  • I am using online style sheet for stling. – Muzammal Hussain Aug 13 '20 at 07:08
  • 1
    Also, see this post: https://stackoverflow.com/questions/17507101/how-to-add-styling-to-a-single-input-in-a-form-for It's in HAML but idea is basically the same – glinda93 Aug 13 '20 at 07:10

1 Answers1

1

You have to put the class behind a comma

<%= text_field 'books' :name, class:"form-control mb-4 col-10", placeholder="Patient name" %>
Spinshot
  • 275
  • 2
  • 12