-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.

4
  • 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? Commented Aug 13, 2020 at 7:05
  • 2
    Does this answer your question? Setting the class of HTML elements using Rails? Commented Aug 13, 2020 at 7:05
  • I am using online style sheet <link rel="stylesheet" href="stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/…" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> for stling. Commented Aug 13, 2020 at 7:08
  • 1
    Also, see this post: stackoverflow.com/questions/17507101/… It's in HAML but idea is basically the same Commented Aug 13, 2020 at 7:10

1 Answer 1

1

You have to put the class behind a comma

<%= text_field 'books' :name, class:"form-control mb-4 col-10", placeholder="Patient name" %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.