RubyBeginner
RubyBeginner

Reputation: 319

formatting a form inside my rails app

I have a rails app with form inside of it. my css file is all ready. i just don't know how to apply the css form classes and ids also to the fields inside of my create action page where my form_for lives?

 <%= form_for @user do |f| %>
  <% if @user.errors.any? %>
    <div class="error_messages">
      <h2>Form is invalid</h2>
      <ul>
        <% for message in @user.errors.full_messages %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  <p>
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </p>
  <p>
    <%= f.label :password %><br />
    <%= f.password_field :password %>
  </p>
  <p>
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation %>
  </p>
  <p class="button"><%= f.submit %></p>
<% end %>

my css styles for the form tag and for its fiels as below:

 id="phx-signup-form"  

e-mail field css style:

 class="email-input"

Upvotes: 0

Views: 872

Answers (3)

Ganesh Kunwar
Ganesh Kunwar

Reputation: 2653

Your form automatically takes id as new_user if your form is running as new form and takes id as edit_user if your form is running as edit form. So you use id="new_user" or id="edit_user" instead of id="phx-signup-form" in your css depending on condition.

For your form and <%= f.text_field :email, "", :class => 'email-input' %> for emai field. Just try it. It may solve your problem.

Upvotes: 0

Thilo
Thilo

Reputation: 17735

A good place to start is the Rails API documentation.

form_for(@user, html: { id: 'phx-signup-form' })

should put you on the right path.

Upvotes: 0

subosito
subosito

Reputation: 3470

Try

<%= form_for @user, :html => { :id => 'phx-signup-form' } do |f| %>

and

<%= f.text_field :email, :class => 'email-input' %>

You can read more references on http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

Upvotes: 2

Related Questions