Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:28:53+00:00 2026-06-02T10:28:53+00:00

My Rails application just wont add any class to fields with errors. Cant find

  • 0

My Rails application just wont add any class to fields with errors. Cant find wihat is the problem.

Got this in model:

validates_presence_of :name
validates_uniqueness_of :name
validates_presence_of :phone

Any ideas where to start looking for solutions ?

This is the view erb file which does not generate the required styled class:

<%= form_for :company, :url => {:action => 'create_lead'}, :html => {:class => "form-horizontal"} do |f|  %>

<div class="">

    <div class="span2"> 
    <%= f.label :csdd_nr, "CSDD numurs" %>
    <%= f.text_field :csdd_nr, {:class => "input-small"} %>
    </div>

    <div class="span4">
    <%= f.label :name, "Nosaukums" %>
    <%= f.text_field :name %>
    </div>

    <div class="span6">
    <%= f.label :ap_veh_count, "Auto skaits" %>
    <%= f.text_field :ap_veh_count, {:class => "input-small"} %><br /><br />
    </div>

    <div class="span6">
    <%= f.label :office_adress_street, "Faktiskā adrese" %>
    <%= f.text_field(:office_adress_street, {:placeholder => 'Iela', :class => "input-medium"}) %> <%= f.text_field(:office_adress_city, {:placeholder => 'Pilsēta', :class => "input-small"}) %> <%= f.text_field(:office_adress_postcode, {:placeholder => 'Pasta indekss', :class => "input-small"}) %>
    </div>

    <div class="span4">
    <%= f.label :web, "Mājaslapa" %>
    <%= f.text_field :web  %><br /><br />
    </div>

    <div class="span4">
    <%= f.label :phone, "Telefona numurs" %>
    <%= f.text_field :phone  %>
    </div>

    <div class="span4">
    <%= f.label :email, "E-pasts" %>
    <%= f.text_field :email  %>
    </div>

    <div class="span4">
    <%= f.label :company_field, "Uzņēmuma nodarbošanās" %>
    <%= f.text_field :company_field %><br /><br />
    </div>

    <%= f.hidden_field(:company_status, :value => "3") %>

    <div class="span12">
    <br /><br />
    <%= submit_tag("Saglabāt", :class => 'btn btn-primary') %>
    <%= link_to "Atcelt", {:action => 'list_leads'}, :class => 'btn' %>
    </div>  def new_lead
    @company = Company.new
end

def create_lead
    @company = Company.new(params[:company])

    if @company.save
        flash[:success] = "Uzņēmums saglabāts"
        redirect_to(:action => 'new_lead')
    else
        flash[:alert] = "!!! Uzņēmums nav saglabāts"
        redirect_to(:action => 'new_lead')
    end
end
</div>

<% end %>

OK, and here is the controller which saves the data to database:

def new_lead
    @company = Company.new
end

def create_lead
    @company = Company.new(params[:company])

    if @company.save
        flash[:success] = "Uzņēmums saglabāts"
        redirect_to(:action => 'new_lead')
    else
        flash[:alert] = "!!! Uzņēmums nav saglabāts"
        redirect_to(:action => 'new_lead')
    end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:28:59+00:00Added an answer on June 2, 2026 at 10:28 am

    This happens because you’re redirecting instead of rendering, when there is a validation error. Your controller should look like:

    def create_lead
      @company = Company.new(params[:company])
    
      if @company.save
        flash[:success] = "Uzņēmums saglabāts"
        redirect_to(:action => 'new_lead')
      else
        flash[:alert] = "!!! Uzņēmums nav saglabāts"
        render(:action => 'new_lead')
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have just deployed my rails application but the css stylesheet wont appear I'm
I just updated to Rails 3.2 and I started to get errors like this:
We've got a Rails application just upgraded to Rails3 using Devise's Rails3 gem for
I just started to document a rails application. I know this is actually done
I just get started using BDD in Rails application, but I'm not sure what
In one of my rails application I have to send a email. I just
I am currently deploying a Rails application using Capistrano. Cap deploy:update_code usually works just
I just upgraded my Leopard system to Snow. I had a Rails application with
I just created a new rails app in Rails 3.1.1, and my application layout
I've just begun creating a rails application using mongomapper for my models. I'm wondering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.