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 8618247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:03:41+00:00 2026-06-12T06:03:41+00:00

I’m using rails 3.2 with active record and sqlserver. I have a problem with

  • 0

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

  • 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-12T06:03:42+00:00Added an answer on June 12, 2026 at 6:03 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.