Multiple records not available when creating .CSV - ruby-on-rails

#orders should have multiple orders yet when using a respond_to to create an CSV, I only have one order record available in my cvs.erb file. Here's the code.
reports_controller.rb
def orders
params[:q] = {} unless params[:q]
if params[:q][:completed_at_gt].blank?
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
else
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
end
if params[:q] && !params[:q][:completed_at_lt].blank?
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
end
params[:q][:s] ||= "completed_at desc"
#search = Order.complete.ransack(params[:q])
#orders = #search.result
respond_to do |format|
format.html
format.csv do
headers['Content-Disposition'] = "attachment; filename=\"Order-List\"#{Date.today}"
headers['Content-Type'] ||= 'text/csv'
end
end
end
order_items.csv.erb
<%- headers = ['Order Number', 'User', 'Item Total', 'Discount Value', 'Sales Total', 'Promotions'] -%>
<%= CSV.generate_line headers %>
<%- #orders.each do |order| -%>
<%= CSV.generate_line([order.number, order.email, order.item_total, order.promo_total, order.total]) %>
<%- end -%>
order_items.html.erb
<%= search_form_for #search, :url => spree.order_items_admin_reports_path do |s| %>
<div class="form-group date-range-filter">
<%= label_tag nil, Spree.t(:date_range) %>
<div class="date-range-filter row">
<div class="col-md-6">
<%= s.text_field :completed_at_gt, :class => 'datepicker datepicker-from form-control', :value => datepicker_field_value(params[:q][:completed_at_gt]) %>
</div>
<div class="col-md-6">
<%= s.text_field :completed_at_lt, :class => 'datepicker datepicker-to form-control', :value => datepicker_field_value(params[:q][:completed_at_lt]) %>
</div>
</div>
</div>
<div class="form-actions">
<%= button Spree.t(:search), 'search' %>
</div>
<%= link_to "Export CSV", order_items_admin_reports_path(format: 'csv', :params[:q] => params[:q]), {:style => 'margin-top: 50px; margin-bottom: 20px;', :class => "btn btn-primary btn-success"} %>
<% end %>

Related

Solr not working Rails

I have this on my view:
<div class='container'>
<div class='row upper_container'>
<div class='search_container'>
<%= form_tag deals_path, :method => :get, :class => 'navbar-form navbar-left' do %>
<div class='form-group'>
<%= text_field_tag :search, params[:search], class: 'form-control' %>
</div>
<%= submit_tag 'Search', :name => nil %>
<% end %>
</div>
</div>
<% #deals.each_with_index do |d, i| %>
<% if i % 3 == 0 %>
<div class='row middle_container'>
<% end %>
<div class='col-md-4'>
<div class='deal_container'>
<%= d.title %>
<img src='<%= d.photo %>', class='deal_img'>
</div>
</div>
<% if (i % 3 == 2) || (i == (#deals.length - 1)) %>
</div>
<% end %>
<% end %>
</div>
this in my controller:
class DealsController < ApplicationController
def index
# #deals = Deal.paginate(:page => params[:page])
#search = Deal.search do
fulltext params[:search]
end
#deals = #search.result
end
private
def deal_params
params.require(:deal).permit(:title)
end
end
and this in my model:
class Deal < ActiveRecord::Base
searchable do
text :title
end
end
when I want to do a seach by some word, like 'Treatment', the #deals variable, in the controller is null, but the param is being sent: Parameters: {"utf8"=>"✓", "search"=>"Treatment"}
any idea?
Try this:
query = params[:search]
#search = Deal.search do
fulltext query
end
#deals = #search.result
Please check this answer for details.

Error ActiveRecord::RecordNotFound (Couldn't find Planner without an ID):

There is something wrong with my code, and I couldn't figure out what is it. It's already one day I'm trying to solve this by googling and searching on Stack Overflow.
Errors:
Processing ClassTimingsController#show (for 127.0.0.1 at 2014-02-05 15:27:19) [POST]
Parameters: {"authenticity_token"=>"sRTUkx7slXEX+kmzNl4GbYSIFSyf1WGSP5fRB5+rPzY=",
"batch_id"=>"13", "_"=>"", "action"=>"show", "controller"=>"class_timings"}
[FedenaRescue] AR-Record_Not_Found Couldn't find Planner without an ID
ActiveRecord::RecordNotFound (Couldn't find Planner without an ID):
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1567:in `
find_from_ids'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:616:in `find'
app/controllers/class_timings_controller.rb:103:in `show'
I guess there is some problem with the "class_timings_controller.rb" in show.
def show
#planner = nil
if params[:planner_id] == ''
#class_timings = ClassTiming.find(:all, :conditions=>["planner_id is null and is_deleted = false"])
else
#class_timings = ClassTiming.active_for_planner(params[:planner_id])
#planner = Planner.find params[:planner_id] unless params[:id] == ''
end
respond_to do |format|
format.js { render :action => 'show' }
end
end
What is my mistake?
Below is the code for MVC.
Model (class_timing.rb)
class ClassTiming < ActiveRecord::Base
belongs_to :batch
belongs_to :planner
validates_presence_of :subject_title
validates_uniqueness_of :subject_title, :scope => [:planner_id , :batch_id, :is_deleted]
named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted=>false, :checklist => false} } }
named_scope :default, :conditions => { :batch_id => nil, :checklist => false, :is_deleted=>false }
named_scope :active_for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted=>false} } }
named_scope :active, :conditions => { :batch_id => nil, :is_deleted=>false }
named_scope :for_planner, lambda { |p| { :conditons => { :planner_id => p.to_i, :is_deleted=>false, :checklist => false} } }
named_scope :default, :conditions => { :planner_id => nil, :checklist => false, :is_deleted=>false }
named_scope :active_for_planner, lambda { |p| { :conditions => { :planner_id => p.to_i, :is_deleted=>false} } }
named_scope :active, :conditions => { :planner_id => nil, :is_deleted=>false }
end
View
index
<div id="content-header">
<%= image_tag("/images/show_timetable.png") %>
<h1><%= t('teaching_schedule') %></h1>
<h3><%= t('create_new_teaching_schedule') %></h3>
<div id="app-back-button">
<%= link_to_function image_tag("/images/buttons/back.png", :border => 0), "history.back()" %>
</div>
</div>
<div id="page-yield">
<div id="flash_box"></div>
<% unless flash[:notice].nil? %>
<p class="flash-msg"> <%= flash[:notice] %> </p>
<% end %>
<div class="label-field-pair">
<label ><%= t('select_a_batch') %>:</label>
<div class="text-input-bg">
<%= select :batch, :id,
#batches.map {|b| [b.full_name, b.id] },
{:prompt => "#{t('common')}"},
{:onchange => "#{remote_function(
:url => { :action => 'show' },
:with => "'batch_id='+value",
:before => "Element.show('loader')",
:success => "Element.hide('loader')"
)}"} %>
<label ><%= t('select_a_module') %>:</label>
<div class="text-input-bg">
<%= select :planner, :id,
#planners.map {|p| [p.name, p.id] },
{:prompt => "#{t('common')}"},
{:onchange => "#{remote_function(
:url => { :action => 'show' },
:with => "'planner_id='+value",
:before => "Element.show('loader')",
:success => "Element.hide('loader')"
)}"} %>
<%= image_tag("loader.gif", :align => "absmiddle", :border => 0, :id => "loader", :style =>"display: none;" ) %>
</div></div></div>
<div id="class-timings-list"><%= render :partial => "show_batch_timing" %></div>
<div id="modal-box" style="display:none;"></div>
<div class="extender"></div>
</div>
show
<div class="linker">
<%= link_to_remote "#{t('add')}", :url => { :action => 'new', :id => #planner , :id => #batch} %>
</div>
<% unless #class_timings.empty? %>
<table id="class-timings-list" width="100%">
<tr class="tr-head">
<td><%= t('subject_title') %></td>
<td><%= t('page_no') %></td>
<td><%= t('duration') %></td>
<td><%= t('checklist') %></td>
<td><%= t('tutor_name') %></td>
<td><%= t('operations') %></td>
</tr>
<% #class_timings.each do |class_timing| %>
<tr id="class-timing-<%= class_timing.id %>" class="tr-<%= cycle('odd','even') %>">
<td class="col-2"><%= class_timing.subject_title %></td>
<td class="col-5" style="text-align:right"><%= class_timing.page_no %></td>
<td class="col-5" style="text-align:right"><%= class_timing.duration %></td>
<td class="col-5" style="text-align:center"><%= check_box_tag(nil, class_timing.checklist, class_timing.checklist, :disabled => true) %></td>
<td class="col-3"><%= class_timing.tutor_name %></td>
<td class="col-3"><small><%= link_to_remote("#{t('edit_text')}",
:url => edit_class_timing_path(class_timing), :method => 'get' ) %> |
<% #tt = PeriodEntry.find_all_by_id(class_timing_id ) %>
<!-- <% #tt = PeriodEntry.find_all_by_class_timing_id(class_timing.id ) %> -->
<% if #tt.empty? %>
<%= link_to_remote("#{t('delete_text')}",
:url => class_timing_path(class_timing),
:method => 'delete',
:confirm => "#{t('confirm_msg')}",
:update => "class-timing-#{class_timing.id}") %>
<% else %>
<s><%= t('delete_text') %></s>
<% end %></small></td>
</tr>
<% end %>
</table>
<% else %>
<h4><%= t('set_in_common') %></h4>
<% end %>
new
<label class="head_label"><%= t('create_new_teaching_schedule_for') %> <br>
<span>
<% if #planner.nil? and #batch.nil? %>
<%= t('common') %>
<% else %>
<%= #planner.name and #batch.full_name %>
<% end %>
</span></label>
<div id="ajax-create">
<% form_remote_for :class_timing,
:url => { :action => 'create'} do |f| %>
<% planner_id = (#planner.nil? ? nil : #planner.id) %>
<% batch_id = (#batch.nil? ? nil : #batch.id) %>
<%= f.hidden_field :planner_id, :value => planner_id %>
<%= f.hidden_field :batch_id, :value => batch_id %>
<div id="form-errors"></div>
<div class="label-field-pair">
<label for="name"><%= t('subject_title') %></label>
<div class="input-field"><%= f.text_field :subject_title %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('page_no') %></label>
<div class="input-field"><%= f.text_field :page_no %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('duration') %></label>
<div class="input-field"><%= f.text_field :duration %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('Completed') %></label>
<div><%= f.check_box :checklist, :checked => false %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('tutor_name') %></label>
<div class="input-field"><%= f.text_field :tutor_name %></div>
</div>
<br>
<br>
<br>
<%= f.submit "? #{t('save')}", :class => 'submit-button' %>
<% end %>
</div>
edit
<label class="head_label"><%= t('edit_teaching_schedule_for') %> <br>
<span>
<% if #planner.nil? and #batch.nil? %>
<%= t('common') %>
<% else %>
<%= #planner.name and #batch.name %>
<% end %>
</span></label>
<div id="ajax-edit">
<% form_remote_for #class_timing do |f| %>
<div id="form-errors"></div>
<div class="label-field-pair">
<label for="name"><%= t('subject_title') %></label>
<div class="text-input-bg"><%= f.text_field :subject_title %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('page_no') %></label>
<div class="text-input-bg"><%= f.text_field :page_no %></div>
</div>
<div class="label-field-pair">
<label for="name"><%= t('duration') %></label>
<div class="text-input-bg"><%= f.text_field :duration %></div>
</div>
<div class="label-field-pair">
<% if #class_timing.checklist %>
<label for="name"><%= t('Completed') %></label>
<div><%= f.check_box :checklist, :checked => true %></div>
<% else %>
<label for="name"><%= t('Completed') %></label>
<div><%= f.check_box :checklist, :checked => false %></div>
<% end %>
</div>
<div class="label-field-pair">
<label for="name"><%= t('tutor_name') %></label>
<div class="input-field"><%= f.text_field :tutor_name %></div>
</div>
<br>
<br>
<br>
<%= submit_tag "? #{t('save')}", :class => 'submit-button' %>
<% end %>
</div>
Controller (class_timings_controller.rb)
class ClassTimingsController < ApplicationController
before_filter :login_required
filter_access_to :all
def index
#batches = Batch.active
#planners = Planner.active
#class_timings = ClassTiming.find(:all,:conditions => { :planner_id => nil, :batch_id => nil, :is_deleted=>false})
end
def new
#class_timing = ClassTiming.new
#batch = Batch.find params[:id] if request.xhr? and params[:id]
#planner = Planner.find params[:id] if request.xhr? and params[:id]
respond_to do |format|
format.js { render :action => 'new' }
end
end
def create
#class_timing = ClassTiming.new(params[:class_timing])
#planner = #class_timing.planner
#batch = #class_timing.batch
respond_to do |format|
if #class_timing.save
#class_timing.planner.nil? and #class_timing.batch.nil? ?
#class_timings = ClassTiming.find(:all,:conditions => { :planner_id => nil,:batch_id => nil,:is_deleted=>false}) :
#class_timings = ClassTiming.for_batch(#class_timing.batch_id)
#class_timings = ClassTiming.for_planner(#class_timing.planner_id)
# flash[:notice] = 'Teaching schedule was successfully created.'
format.html { redirect_to class_timing_url(#class_timing) }
format.js { render :action => 'create' }
else
#error = true
format.html { render :action => "new" }
format.js { render :action => 'create' }
end
end
end
def edit
#class_timing = ClassTiming.find(params[:id])
respond_to do |format|
format.html { }
format.js { render :action => 'edit' }
end
end
def update
#class_timing = ClassTiming.find params[:id]
respond_to do |format|
if #class_timing.update_attributes(params[:class_timing])
#class_timing.planner.nil? and #class_timing.batch.nil? ?
#class_timings = ClassTiming.find(:all,:conditions => { :planner_id => nil, :batch_id => nil}) :
#class_timings = ClassTiming.for_batch(#class_timing.batch_id)
#class_timings = ClassTiming.for_planner(#class_timing.planner_id)
# flash[:notice] = 'Teaching schedule updated successfully.'
format.html { redirect_to class_timing_url(#class_timing) }
format.js { render :action => 'update' }
else
#error = true
format.html { render :action => "new" }
format.js { render :action => 'create' }
end
end
end
def show
#batch = nil
if params[:batch_id] == ''
#class_timings = ClassTiming.find(:all, :conditions=>["batch_id is null and is_deleted = false"])
else
#class_timings = ClassTiming.active_for_batch(params[:batch_id])
#batch = Batch.find_by_id params[:batch_id] unless params[:batch_id] == ''
end
#planner = nil
if params[:planner_id] == ''
#class_timings = ClassTiming.find(:all, :conditions=>["planner_id is null and is_deleted = false"])
else
#class_timings = ClassTiming.active_for_planner(params[:planner_id])
#planner = Planner.find_by_id params[:planner_id] unless params[:planner_id] == ''
end
respond_to do |format|
format.js { render :action => 'show' }
end
end
def destroy
#class_timing = ClassTiming.find params[:id]
#class_timing.update_attribute(:is_deleted,true)
end
end
I provide all the code to help you figure out better, although I knew some of the code is irrelevant to show.
params[:planner_id] or params[:id]
is not passed properly I guess..
Use Planner.find_by_id params[:planner_id]
You're not passing params[:planner_id] into your controller, therefore it is nil, not ''.
So the else on your conditional is being invoked, and you're calling Planner.find nil.
Change this by calling if params[:planner_id].present? instead.
Try this out:
#planner = Planner.find params[:planner_id] if params[:id].present?
present? will take care of nil, blank, etc.

How to writer strong_params rails4

I am not getting exact solution for finding the strong params for given parameters.
Please help me on this
"service"=>{"1"=>{"client_id"=>"testid", "client_secret"=>"testsecret"}, "2"=>{"client_id"=>"testkey", "client_secret"=>""}, "3"=>{"client_id"=>"", "client_secret"=>""}}
I tried
def service_params
params.require(:service).permit(:id, :client_id, :client_secret)
end
I am getting error
Unpermitted parameters: 1, 2, 3
EDIT:
my form is
<%= form_for :service, :url => update_config_path, :html => { :class => "form-horizontal", :method => "put", :remote => true } do %>
<% #services.each do |s| %>
<%= fields_for "service[]", s do |service_field| %>
<fieldset>
<legend><%= s.name %></legend>
<div class="form-group">
<%= service_field.label :client_id, "Consumer Key", :class => "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= service_field.text_field :client_id, :class => "form-control" %>
</div>
</div>
<div class="form-group">
<%= service_field.label :client_secret, "Consumer Secret", :class => "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= service_field.text_field :client_secret, :class => "form-control" %>
</div>
</div>
</fieldset>
<% end %>
<% end %>
<%= submit_tag %>
<% end %>
I haven't tested it, but something like this might work:
def service_params
params.require(:service).map do |_, p|
p.permit(:id, :client_id, :client_secret)
end
end
Something like this could work:
def service_params
params.require(:service).permit.tap do |whitelisted|
whitelisted["1"] = params["1"]
whitelisted["2"] = params["2"]
whitelisted["3"] = params["3"]
end
end

Ajax action won't reflect on appearance but the value. Why?

I'm using Rails3. Now trying to implement follow button in index.html.erb just like twitter.
It shows member list and their follow buttons.
It looks okay but if I press any of those follow button, appearance doesn't change.
It should changes follow to un-follow right away.
I have no idea why it does. But if I reload the page, it shows correct status.
follows_controller.rb
class FollowsController < ApplicationController
def create
#user = User.find(params[:user_id])
current_user.follow(#user)
respond_to do |format|
format.js {render :action=>"create.js"}
end
end
def destroy
#user = User.find(params[:user_id])
current_user.stop_following(#user)
respond_to do |format|
format.js {render :action=>"destroy.js"}
end
end
end
views/users/_follow_user.html.erb
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= button_to("Un-Follow", user_follow_path(user.to_param, current_user.get_follow(user).id),
:method => :delete,
:remote => true,
:class => 'btn') %>
<% else %>
<%= button_to("Follow", user_follows_path(user.to_param),
:remote => true,
:class => 'btn btn-primary') %>
<% end %>
<% end %>
views/users/create.js.erb
$('.follow_user[data-user-id="<%=#user.id%>"]').html('<%= escape_javascript(render :partial => "follow_user", :locals => {:user => #user}) %>');
#jQuery
views/users/destroy.js.erb
$('.follow_user[data-user-id="<%=#user.id%>"]').html('<%= escape_javascript(render :partial => "follow_user", :locals => {:user => #user}) %>');
#jQuery
views/users/index.html.erb
<%- model_class = User.new.class -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
</div>
<% #from %>
<h3>tag cloud</h3>
<% tag_cloud(#tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
<%= link_to tag.name, {:action=>'index', :tag=>tag.name}, :class => css_class%>
<% end %>
<%= paginate #users %>
<table class="table table-condensed">
<thead></thead>
<tbody>
<% #users.each do |user| %>
<div class="memberListBox">
<div class="memberList">
<p class="name"><span><%= user.user_profile.nickname %></span>(<%= user.user_profile.age %>)</p>
<p class="size"><%= user.username %></p>
<p class="img">
<% if user.user_profile.user_avatar? %>
<%= image_tag(user.user_profile.user_avatar.url(:thumb),:height => 100, :width => 100, :class => 'img-polaroid' ) %>
<% else %>
<%= image_tag('nophoto.gif',:height => 100, :width => 100, :class => 'img-polaroid' ) %>
<% end %>
</p>
<div class="introduction">
<%= user.user_profile.introduction %>
</div>
<% if user_signed_in? && current_user!=user %>
<div id="follow_user">
<%= render :partial => "follow_user", :locals => {:user => user} %>
</div>
<% end %>
<%= link_to sanitize('<i class="icon-pencil icon-white"></i> ') + 'Message', new_messages_path(user.username), :class => 'btn btn-primary' %>
<%= link_to sanitize('<i class="icon-user icon-white"></i> ') + 'Profile', show_user_path(:username => user.username, :breadcrumb => #from), :class => 'btn btn-info' %>
</div>
</div>
<% end %>
</tbody>
</table>
response content
$('#follow_user').html(' <form action=\"/users/1/follows\" class=\"button_to\" data-remote=\"true\" method=\"post\"><div><input class=\"btn btn-primary\" type=\"submit\" value=\"Follow\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"G/taOUeWy2gumhWUi10cPvECAmYLQdhQ2/eGGMJwvPE=\" /><\/div><\/form>\n');
Add the user id to the attribute data-user-id and add the class follow_user
<div class="follow_user" data-user-id="<%= user.id %>">
<%= render :partial => "follow_user", :locals => {:user => user} %>
</div>

div class wrapping fieldwitherrors won't work

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

Resources