0
我的Rails應用程序不會將任何類添加到有錯誤的字段。不能找到問題所在。div class wrapring fieldwitherrors將不起作用
模型得到這個:
validates_presence_of :name
validates_uniqueness_of :name
validates_presence_of :phone
任何想法從哪裏開始尋找解決方案?
這是視圖ERB文件,它不會產生所需的樣式類:
<%= 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,這裏是將數據保存到數據庫中的控制器:
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
您發佈應該是模型的代碼。你的意思是對某些元素的HTML類嗎?然後你應該發佈表單的ERB/HAML標記。 – Alex 2012-04-17 10:37:18
我錯了,這是來自模型。將張貼erb。 – kipeens 2012-04-17 10:38:19
你還可以發佈保存模型的控制器代碼嗎? – tsherif 2012-04-17 11:03:11