i have two models department and address and they are associated
with one another but when i use client side form validation address
model fields are not getting validated. The javascript for
validating associated model is not being generated.
Department model
class Department < ActiveRecord::Base
attr_accessible :agency_head, :agency_head_rank, :department_type_id, :fax, :name,
:phone, :address_attributes
validates :name , :length => { :minimum => 2 } , :presence => true
validates :department_type_id , :agency_head,:agency_head_rank,:phone,:fax, :presence => true
belongs_to :department_type
belongs_to :address, :class_name => "Address", :foreign_key => "address_id"
accepts_nested_attributes_for :address,:allow_destroy => true
end
Address model
class Address < ActiveRecord::Base
attr_accessible :state, :street1, :street2, :town, :zipcode, :county
validate :street1 ,:street2,:town,:state,:county,:zipcode ,:presence => true
has_one :department
end
view-page
<h1 id="form-title">Add New Department</h1>
<%=form_for #department ,:validate=>true do |f|%>
<div id="respond">
<% if #department.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#department.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #department.errors.full_messages.each do |msg| %>
<li>
<%= msg %>
</li>
<% end %>
</ul>
</div>
<% end %>
<p class="comment-form-author">
<label for="Department Name">Department Name</label><span class="required">*</span>
<%= f.text_field :name, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="Department Type">Department Type</label>
<%= f.collection_select :department_type_id, #dept_types, :id, :name, :prompt => true %>
</p>
<%= f.fields_for :address, #department.address ,:validate=> true do |addr| %>
<p class="comment-form-author">
<label for="Street1">Street 1</label>
<%= addr.text_field :street1 , :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="Street 2">Street 2</label>
<%= addr.text_field :street2, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="Town">Town</label>
<%= addr.text_field :town, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="State">State</label>
<%= addr.text_field :state, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="State">County</label>
<%= addr.text_field :county, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="Zip Code">Zip Code</label>
<%= addr.text_field :zipcode, :size => 30, 'aria-required' => 'true' %>
</p>
<% end %>
<p class="comment-form-author">
<label for="agency head">Agency Head</label><span class="required">*</span>
<%= f.text_field :agency_head, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="agency head rank">Agency Head Rank</label><span class="required">*</span>
<%= f.text_field :agency_head_rank, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="phone">Phone</label><span class="required">*</span>
<%= f.text_field :phone, :size => 30, 'aria-required' => 'true' %>
</p>
<p class="comment-form-author">
<label for="fax">Fax</label><span class="required">*</span>
<%= f.text_field :fax, :size => 30, 'aria-required' => 'true' %>
</p>
</div>
<div class="spacer">
<br/>
<center>
<%= f.button " Submit ", :id => 'my_login_form_button' %>
</center> </div> <% end %> </div> </div> </div> </div> </div>
You can use Jquery validate to validate your forms. It is much easier than doing it manually.
I find out my mistake use this one in address model.
validates :street1 ,:street2,:town,:state,:county,:zipcode ,:presence => true
Related
I have a webpage with a list of offices. Currently I'm trying to make three forms for editing/adding/deleting an office. This is what I have:
A model:
class ChangeOfficeAddress < ApplicationRecord
belongs_to :office
belongs_to :insurer
belongs_to :city
VALID_EMAIL_REGEX = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
validates_presence_of :email
validates_format_of :email, with: VALID_EMAIL_REGEX
validates_presence_of :edit_office_address
validates_presence_of :add_office_address
validates_presence_of :delete_office_address
validates_presence_of :city_id
validates_presence_of :insurer_id
validates_presence_of :name
end
In a view I have my modals in partials:
<div id="addModal" class="modal fade" role="dialog" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="text-center">
<div class="btn-group topbar header-buttons" role="group" aria-label="...">
<%= link_to 'Add', '#', class: 'btn btn-default disabled' %>
<%= link_to 'Edit', '#editModal', { 'class' => 'btn btn-default', 'data-toggle' => 'modal', 'data-dismiss' => 'modal' } %>
<%= link_to 'Delete', '#deleteModal', { 'class' => 'btn btn-default', 'data-toggle' => 'modal', 'data-dismiss' => 'modal' } %>
</div>
</div>
</div>
<div class="modal-body">
<%= form_for (#change_office_address), remote: true, format: :json, html: { class: :contact_form } do |f| %>
<div id="error_explanation" style='display:none;' class="bg-danger text-danger alert fade in alert-danger alert-dismissable errors">
<ul>
<% if #change_office_address.errors.any? %>
<% #change_office_address.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
<% end %>
</ul>
</div>
<%= f.text_field :name, placeholder: 'Name', class: 'form-control' %>
<br>
<%= f.text_field :email, placeholder: 'e-mail', class: 'form-control' %> <br>
<%= f.label :city_id %>
<%= f.collection_select :city_id, City.order(:name), :id, :name,
{ include_blank: true }, { class: 'form-control' } %>
<br>
<%= f.label :insurer_id, 'Insurer' %>
<%= f.collection_select :insurer_id, Insurer.order(:short_name), :id, :short_name,
{ include_blank: true }, { class: 'form-control' } %>
<br>
<%= f.text_area :add_office_address, placeholder: 'Add address', class: 'form-control', cols: '30',
rows: '5' %> <br>
<div class="text-center">
<%= f.submit, class: 'btn btn-default' %>
</div>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
And two other modals, the only differences between them is that :add_office_address is substituted with :edit_office_address and :delete_office_address.
When there are no validations in the model, the form submits, and everything is Ok, but when I add validations to :add_office_address, :edit_office_address and :delete_office_address, the validation doesn't pass, cause these fields(I mean :edit_office_address, :delete_office_address or :add_office_address) are blank.
How can I make different forms? Thanks ahead!
For some context, what are the reasons for different fields for [add|edit|delete]_office_address?
However, to solve your issue, you should probably do something like:
class ChangeOfficeAddress < ApplicationRecord
belongs_to :office
belongs_to :insurer
belongs_to :city
VALID_EMAIL_REGEX = /\A[\w+\-.]+#[a-z\d\-.]+\.[a-z]+\z/i
validates_presence_of :email
validates_format_of :email, with: VALID_EMAIL_REGEX
validates_presence_of :edit_office_address, if: :edit_office_address_changed?
validates_presence_of :add_office_address, if: :add_office_address_changed?
validates_presence_of :delete_office_address, if: :delete_office_address_changed?
validates_presence_of :city_id
validates_presence_of :insurer_id
validates_presence_of :name
end
Let me know if that works.
Friends , I have a model order that has many details. I am using the cocoon gem to generate forms . They render ok but are not saving . I click the button to save and nothing happens , and rails console shows nothing. The default edit form, called detail_fields saves with no problem. But i had to create this one called detail_fields_dev, and this one is not working. Can someone help?
routes.rb
resources :details
resources :orders
get '/orders/:id/devolucao' => 'orders#devolucao' , as: 'devolucao_order'
put '/orders/:id' => 'orders#update'
patch '/orders/:id' => 'orders#update'
orders_controller, is ok, using the default rails code. I created this action to call the detail_fields_dev form:
def devolucao
# #order = Order.find(params[:id])
end
The details params are ok too:
def order_params
params.require(:order).permit(:customer_id, :valor_total, :valor_total_dev, :item_total, :item_total_dev,:tipo,:descontado,:order_num, details_attributes: [:id,:order_id, :cod_produto, :desc_produto, :cod_cor, :desc_cor, :desc_tamanho,:preco,:quantidade,:quantidade_dev,:total, :total_dev,:barcode, :_destroy])
end
Order view:
_form_devolucao.html.erb
<%= simple_form_for(#order) do |f| %>
<%= f.error_notification %>
<div class="form-inputs form_fixed">
<%= f.input :customer, :as => :hidden %>
<%= f.input :tipo, :as => :hidden %>
<%= f.input :descontado, :as => :hidden %>
<%= f.input :valor_total, :as => :hidden %>
<%= f.input :item_total, :as => :hidden %>
<%= f.input :order_num, :as => :hidden %>
<div class="row">
<form action="#" method="post">
<div class="small-6 medium-3 columns leitor_dev">
Código de barras
(Leitor):
<input class = "cod_barras_dev" type="text" name="cod_barras_dev" value="" />
</div>
</form>
<div class="small-5 columns end not_found">
<span class="not_found">Produto não existe neste pedido!</span>
</div>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<hr/>
<div id="details">
<%= f.simple_fields_for :details do |detail| %>
<%= render partial: "orders/detail_fields_dev", locals: {f: detail} %>
<% end %>
</div>
<hr/>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<div class="form-actions container">
<%= link_to_add_association '+ ítens', f, :details, data: {"association-insertion-method" => :before, "association-insertion-node" => ".container " },:class => "button tiny radius add" %>
<br />
<br />
<br />
</div>
</div>
</div>
<div class="row">
<div class="small-6 medium-2 columns">
<%= f.button :submit, "Salvar" %>
</div>
<div class="small-6 medium-2 columns end">
<%= link_to 'Cancelar', orders_path, :class => "button alert"%>
</div>
</div>
<% end %>
And the partial orders/detail_fields_dev.html.erb
<div class="nested-fields">
<div class="row listCod" data-cod="<%= f.object.barcode %>">
<div class="small-6 columns show-for-small-only">
<%= f.input :barcode, label: "Cod Barras", input_html: { class: 'barcode_ror_dev' } %>
</div>
<%= f.input :order_id, :as => :hidden, input_html: { class: 'order_id_ror_dev' } %>
<div class="show-for-medium-up small-2 columns">
<%= f.input :cod_produto, label: "Produto", input_html: { class: 'cod_produto_ror_dev' } %>
</div>
<%= f.input :desc_produto,:as => :hidden, input_html: { class: 'desc_produto_ror_dev' } %>
<%= f.input :cod_cor,:as => :hidden, input_html: { class: 'cod_cor_ror_dev' } %>
<div class="small-2 show-for-medium-up columns">
<%= f.input :desc_cor,label: "Cor", input_html: { class: 'desc_cor_ror_dev' } %>
</div>
<div class="small-2 show-for-medium-up columns">
<%= f.input :desc_tamanho,label: "Tam", input_html: { class: 'desc_tamanho_ror_dev' } %>
</div>
<div class="small-2 show-for-medium-up columns">
<%= f.input :preco,label: "Preço",input_html: { class: 'preco_ror_dev' } %>
</div>
<div class="small-6 medium-2 columns">
<%= f.input :quantidade_dev,label: "Qtd Dev", input_html: { class: 'quantidade_ror_dev' } %>
</div>
<div class="show-for-medium-up medium-2 columns end">
<%= f.input :total_dev,label: "Total Dev",input_html: { class: 'total_ror_dev' } %>
</div>
<div class="small-1 columns end">
<%= link_to_remove_association "-", f, :class => "button tiny alert remove"%>
</div>
</div>
</div>
Output:
!(http://imgur.com/kVPpwY6)
Below is my api model:
class Api < ActiveRecord::Base
validates_presence_of :name
belongs_to :service
has_many :statuses
accepts_nested_attributes_for :statuses, reject_if: proc { |attributes| attributes['name'].blank? }
end
Below is my description model:
class Description < ActiveRecord::Base
validates_presence_of :value
belongs_to :status
end
Below is my status model:
class Status < ActiveRecord::Base
belongs_to :api
has_many :descriptions
accepts_nested_attributes_for :descriptions, reject_if: proc { |attributes| attributes['value'].blank? }
end
And below is my new and create action of controller:
def new
#api = Api.new
#status = #api.statuses.new
#status.descriptions.new
end
def create
#api = Api.new(api_params)
if #api.save
flash[:info] = request.original_url + ".do?apiname=" + "#{#api.name}"
redirect_to root_path
else
#api.statuses.new
render :new
end
private
def api_params
params.require(:api).permit(:name, statuses_attributes: [:name, descriptions_attributes:[:value]])
end
Below is my new template:
<div class="form-horizontal">
<%= form_for #api, :url => commons_path do |f| %>
<div class="form-group">
<%= f.label :name, "API Name", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :statuses do |status| %>
<div class="form-group">
<%= status.label :name, "Status", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= status.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :description do |description| %>
<div class="form-group">
<%= description.label :value, "Body", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= description.text_area :value, class: "form-control", rows: 12, cols: 65 %>
</div>
</div>
<% end %>
<% end %>
<%= f.submit("Create Data", class: 'btn btn-primary col-sm-offset-2') %>
<%= link_to "Cancel", root_path, class: "btn btn-danger" %>
<% end %>
After I create new data.It seems like only description's value did not save to my data base. and find an error "Unpermitted parameter: description" in my console.
Any one know what happen?
<div class="form-horizontal">
<%= form_for #api, :url => commons_path do |f| %>
<div class="form-group">
<%= f.label :name, "API Name", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= f.text_field :name, class: "form-control" %>
</div>
</div>
<%= f.fields_for :statuses do |status| %>
<div class="form-group">
<%= status.label :name, "Status", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= status.text_field :name, class: "form-control" %>
</div>
</div>
<%= status.fields_for :descriptions do |description| %>
<div class="form-group">
<%= description.label :value, "Body", class: "col-sm-2 control-label" %>
<div class="col-sm-8">
<%= description.text_area :value, class: "form-control", rows: 12, cols: 65 %>
</div>
</div>
<% end %>
<% end %>
<%= f.submit("Create Data", class: 'btn btn-primary col-sm-offset-2') %>
<%= link_to "Cancel", root_path, class: "btn btn-danger" %>
<% end %>
I am new to rails, And stuck in this problem from last two days
I have a student and student_parent model they have a one-to-many relationship i want to build database attribute through one object from form to datase.
controller's method
def new
#student = Student.new
1.times{ #student.student_parents.build }
.....
.....
end
Create Method:-
def create
#student = Student.new(params[:student])
respond_to do |format|
if #student.save
format.html { redirect_to Student, notice: 'Student was successfully created.' }
format.json { render json: #student, status: :created, location: #student }
else
format.html { render action: "new" }
format.json { render json: #student.errors, status: :unprocessable_entity }
end
end
end
Model:-
class Student < ActiveRecord::Base
include ErrorMessages
belongs_to :user
has_many :student_parents
attr_accessible :birth_date, :blood_group, :first_name, :gender, :last_name, :middle_name,
:school_name, :student_rollno, :email, :user_id, :student_parents_attributes
accepts_nested_attributes_for :student_parents
end
form:-
<%= simple_form_for #student, :html => { :class => 'form-horizontal' } do |f| %>
<div class="row-fluid">
<div class="span3">
<%= f.label :first_name, :class => 'control-label',:required => true %>
<%= f.text_field :first_name %>
</div>
<div class="span3">
<%= f.label :middle_name, :class => 'control-label'%>
<%= f.text_field :middle_name %>
</div>
<div class="span3">
<%= f.label :last_name, :class => 'control-label',:required => true %>
<%= f.text_field :last_name %>
</div>
</div>
<div class="control-group">
<label class = "control-label"> Email </label>
<div class="controls">
<%= f.text_field :email, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<label class = "control-label"> Birth Date <abbr title="required">*</abbr></label>
<div class="controls">
<%= f.text_field :birth_date, :class => 'text_field' ,'data-behaviour' => 'datepicker' %>
</div>
</div>
<% model_class = StudentParent %>
<div class="page-header">
<h4> Parent Information</h4>
</div>
<%= f.fields_for :student_parents do |student_parent| %>
<div class="row-fluid">
<!--<div class="span9">-->
<h5> Father Name </h5>
<div class="span3">
<%= student_parent.label :first_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :first_name %>
</div>
<div class="span3">
<%= student_parent.label :middle_name, :class => 'control-label'%>
<%= student_parent.text_field :middle_name %>
</div>
<div class="span3">
<%= student_parent.label :last_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :last_name %>
</div>
</div>
<div class="row-fluid">
<h5> Mother Name </h5>
<div class="span3">
<%= student_parent.label :first_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :first_name %>
</div>
<div class="span3">
<%= student_parent.label :middle_name, :class => 'control-label'%>
<%= student_parent.text_field :middle_name %>
</div>
<div class="span3">
<%= student_parent.label :last_name, :class => 'control-label',:required => true %>
<%= student_parent.text_field :last_name %>
</div>
</div>
<% end %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
students_path, :class => 'btn' %>
</div>
when submit it only build student information in student table and mother information in student_parent table. But it miss the parent information.
I'm using rails 3.2 with active record and sqlserver. I have a problem with nested forms. I have a model registration which has many registration details and each has a person associated.
Here is the model
class Registration < ActiveRecord::Base
set_table_name "dbo.EV_INSCRIPCIONES"
set_primary_key "Id"
belongs_to :category, :foreign_key => 'CategoriaId'
has_many :registrationDetails, :foreign_key => 'InscripcionEventoId'
#has_one :group
accepts_nested_attributes_for :registrationDetails
validates_associated :registrationDetails
validates :Refencia, :presence => true
#validates_presence_of :category_id
attr_accessible :registrationDetails, :category, :Eliminada, :FechaInscripcion, :CreationalDate, :Referencia, :PagoRegistrado, :Acreditado, :registrationDetails_attributes
#after_initialize :init
def init
write_attribute :Eliminada, false
write_attribute :Acreditado, false
write_attribute :PagoRegistrado, false
write_attribute :CreationalDate, DateTime.now
write_attribute :FechaInscripcion, DateTime.now
#write_attribute :Referencia, ''
end
def category_id
self.category.id unless category.nil?
end
def category_id=(id)
self.category = Category.find(id)
end
end
class RegistrationDetail < ActiveRecord::Base
set_table_name "dbo.EV_INSCRIPCION_DETALLE"
set_primary_key "Id"
belongs_to :registration, :foreign_key => 'InscripcionEventoId'
belongs_to :category, :foreign_key => 'CategoriaId'
belongs_to :person, :foreign_key => 'ParticipanteId', :primary_key => 'JUGADOR_ID'
attr_accessible :person, :category, :registration, :Eliminada, :person_attributes
accepts_nested_attributes_for :person
validates_associated :person
after_initialize :init
def init
write_attribute :Eliminada, false
end
end
class Person < ActiveRecord::Base
set_table_name "dbo.PKR_JUGADOR"
set_primary_key "JUGADOR_ID"
has_many :registrationDetails
validates_presence_of :CDNI, :CNOMBRES, :CAPELLIDO, :CSEXO,:CCIUDADRESIDENCIA, :DFECHANACIMIENTO
validates :CDNI, :length => { :minimum => 7, :maximum =>8 }
#validate :validate_birth_date
before_save :set_ids
def set_ids
if id.nil?
_id = Person.maximum(:JUGADOR_ID)
self.JUGADOR_ID = _id +1
write_attribute :CNROJUGADOR, _id+1
end
end
after_initialize :init
def init
write_attribute :TIPODOCUMENTO_ID, 1 if read_attribute(:TIPODOCUMENTO_ID).nil?
end
def full_name
self.surname + ", " + self.name
end
protected
def validate_birth_date
errors.add(:birth_date, 'must be a valid datetime') if ((Date.strptime(birth_date, "%d/%m/%Y") rescue ArgumentError) == ArgumentError)
end
end
My view
index.html.erb
<h1><%= t '.title', :name => #event.CNOMBRETORNEO %> </h1>
<%= render 'form_nested' %>
_form_nested
<%= form_for #registration, :url => {:controller => "registration", :action => "save"}, :html => {:class=> 'form-horizontal'} do |f| %>
<legend><%= t '.legend' %></legend>
<% if f.object.errors.any?%>
<div id="error_explanation">
<h3 class="text-error"><%= t '.has-errors' %></h3>
</div>
<% end %>
<input type="hidden" id="event_date" name="event_date" value="<%= #event.DDIAACTIVIDAD.strftime('%Y%m%d') %>" />
<input type="hidden" id="event_id" name="event_id" value="<%= #event.TORNEOPOKER_ID %>" />
<%= f.fields_for :registrationDetails do |d| %>
<%= render 'details_fields' , :f => d %>
<% end %>
<% has_error = f.object.errors.has_key? :category %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :category, :class=> 'control-label' %>
<div class="controls">
<%= f.hidden_field :category_id %>
<div class="btn-group" data-toggle-name="presenter_category_id" data-toggle="buttons-radio">
<%#categorias.each do |x| %>
<button value="<%= x.Id %>" type="button" class="btn" data-age-from="<%= x.FromAge %>" data-age-to="<%= x.ToAge %>"><%= x.Name %></button>
<%end %>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:category].join(", ")%></span>
<% end %>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary"><%= t '.save' %></button>
</div>
<%end%>
_detatails_fields
<%= f.object.errors.inspect %>
<%= f.fields_for :person do |p| %>
<%= render 'person_fields', :f => p %>
<% end %>
_person_fields
<%= f.hidden_field :id %>
<% has_error = f.object.errors.has_key? :CDNI %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :CDNI, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-book"></i></span>
<%= f.text_field :CDNI, :class => 'input' %>
<div class="add-on" id="document_loader"><%= image_tag '6-0.gif' %></div>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:CDNI].join(", ")%></span>
<% end %>
</div>
</div>
<% has_error = f.object.errors.has_key? :DFECHANACIMIENTO %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :DFECHANACIMIENTO, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-calendar"></i></span>
<%= f.text_field :DFECHANACIMIENTO, :class=>'input' %>
<span id="person_age" class="add-on"></span>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:DFECHANACIMIENTO].join(", ")%></span>
<% end %>
</div>
</div>
<% has_error = f.object.errors.has_key? :CNOMBRES %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :CNOMBRES, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-user"></i></span>
<%= f.text_field :CNOMBRES,:class=>'input' %>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:CNOMBRES].join(", ")%></span>
<% end %>
</div>
</div>
<% has_error = f.object.errors.has_key? :CAPELLIDO %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :CAPELLIDO, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-user"></i></span>
<%= f.text_field :CAPELLIDO,:class=>'input' %>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:CAPELLIDO].join(", ")%></span>
<% end %>
</div>
</div>
<div class="control-group">
<%= f.label :CTELEFONO, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-certificate"></i></span>
<%= f.text_field :CTELEFONO,:class=>'input' %>
</div>
</div>
</div>
<% has_error = f.object.errors.has_key? :CSEXO %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :CSEXO, :class=> 'control-label' %>
<div class="controls">
<%= f.hidden_field :CSEXO %>
<div class="btn-group" data-toggle-name="presenter_sex" data-toggle="buttons-radio">
<button type="button" class="btn" value="M"><%= t '.masculine' %></button>
<button type="button" class="btn" value="F"><%= t '.femenine' %></button>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:CSEXO].join(", ")%></span>
<% end %>
</div>
</div>
<% has_error = f.object.errors.has_key? :CCIUDADRESIDENCIA %>
<div class="control-group<%= " error" if has_error %>">
<%= f.label :CCIUDADRESIDENCIA, :class=> 'control-label' %>
<div class="controls">
<div class="input-append">
<span class="add-on"><i class="icon-map-marker"></i></span>
<%= f.text_field :CCIUDADRESIDENCIA,:class=>'input' %>
</div>
<% if has_error %>
<span class="help-inline"><%=f.object.errors[:CCIUDADRESIDENCIA].join(", ")%></span>
<% end %>
</div>
</div>
And finally the controller
class RegistrationController < ApplicationController
def index
date = "20120729"
id = 1
#id = params[:event_id] unless params[:event_id].nil?
#date = params[:event_date] unless params[:event_date].nil?
#event = Event.find(date,id)
#groups = Group.all
#categorias = Category.where("DiaActividad = ? and TorneoId = ?", date, id)
#registration = Registration.new
#registration.registrationDetails.build( :person => Person.new)
end
def save
#registration = Registration.new(params[:registration])
if #registration.save
redirect_to :controller => 'home'
else
date = params[:event_date]
id = params[:event_id]
#event = Event.find(date,id)
#groups = Group.all
#categorias = Category.where("DiaActividad = ? and TorneoId = ?", date, id)
render :action => 'index'
end
end
end
What is happening? well first of all, the changes on any field are not saved, and the validations are not displayed. When i submit the form, it returns to the same page, and seems the form has errors but no one is displayed, and the data is lost.
Hope you can help me.
Thanks in advance
Well, I don´t Know why but I solved using resources.
In my routes.rb file
resources :registrations
Before I have something like this.
match 'registration/(:event_date)/(:event_id)' => 'registration#index'
match 'registration/save' => 'registration#save'
I think the problem was my custom routes. But i really don`t know.