Foros del Web » Programando para Internet » Ruby »

Multi-Steps Forms y relaciones One- To many

Estas en el tema de Multi-Steps Forms y relaciones One- To many en el foro de Ruby en Foros del Web. Hola A todos!! bueno tengo un pequenio gran problema.. He Creado un Sccafold de Social Card Este es el modelo class SocialCard < ActiveRecord::Base has_many ...
  #1 (permalink)  
Antiguo 22/10/2011, 10:23
Avatar de marieta_lovegood  
Fecha de Ingreso: julio-2009
Ubicación: Cochabamba, Bolivia, Bolivia
Mensajes: 24
Antigüedad: 9 años, 3 meses
Puntos: 0
Multi-Steps Forms y relaciones One- To many

Hola A todos!! bueno tengo un pequenio gran problema..

He Creado un Sccafold de Social Card

Este es el modelo

class SocialCard < ActiveRecord::Base
has_many :helps , :dependent =>:destroy
accepts_nested_attributes_for :helps


attr_accessible :date ,:parish_church,:name, :marital_status, :gender, :birthday, :birthday_location, :identity_card, :phone, :movil, :address, :location_reference, :grade_school, :occupation , :family_members,:parish_belongs, :family_history, :derivative_by, :reference_person, :address_reference, :phone_reference, :movil_reference, :age_reference, :occupation_reference, :type_of_case, :did_you_get_another_help, :helps ,:what_is_persons_problem , :type_of_help, :was_derive_to_some_institution, :date_of_help, :detail, :observation
attr_writer :current_step

validates_presence_of :parish_church, :if => lambda { |o| o.current_step == "personal" }
validates_uniqueness_of :name, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :name, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :birthday, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :birthday_location, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :address, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :identity_card, :if => lambda { |o| o.current_step == "personal" }
validates_numericality_of :phone, :greater_than => 1000000, :less_than => 9999999,:allow_blank => true , :message => "El Telefono no es un numero o es incorrecto" , :if => lambda { |o| o.current_step == "personal" }
validates_numericality_of :movil, :greater_than => 10000000, :less_than => 99999999,:allow_blank => true ,:message => "El Celular no es un numero o es incorrecto" , :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :occupation, :if => lambda { |o| o.current_step == "personal" }
validates_presence_of :family_members, :if => lambda { |o| o.current_step == "personal" }

validates_presence_of :reference_person, :if => lambda { |o| o.current_step == "reference" }
validates_presence_of :phone_reference, :if => lambda { |o| o.current_step == "reference" }
validates_numericality_of :phone_reference, :greater_than => 1000000, :less_than => 9999999,:allow_blank => true , :message => "El Telefono no es un numero o es incorrecto" , :if => lambda { |o| o.current_step == "reference" }
validates_numericality_of :movil_reference, :greater_than => 10000000, :less_than => 99999999,:allow_blank => true ,:message => "El Celular no es un numero o es incorrecto" , :if => lambda { |o| o.current_step == "reference" }
validates_presence_of :occupation_reference, :if => lambda { |o| o.current_step == "reference" }

def current_step
@current_step || steps.first
end

def steps
%w[personal reference helps confirmation]
end

def next_step
self.current_step = steps[steps.index(current_step)+1]
end

def previous_step
self.current_step = steps[steps.index(current_step)-1]
end

def first_step?
current_step == steps.first
end

def last_step?
current_step == steps.last
end

def all_valid?
steps.all? do |step|
self.current_step = step
valid?
end
end
end



como veran ya esta lo del multi steps y bla bla bla .. como al relacion

a Help Este es el modleo Help

class Help < ActiveRecord::Base
belongs_to :social_card
attr_accessible :what_is_persons_problem, :type_of_help, :was_derive_to_some_institution, :date_of_help, :detail, :observation
attr_writer :current_step
end


ahora el controlador de social card

class SocialCardsController < ApplicationController
# GET /social_cards
# GET /social_cards.xml
def index
@social_cards = SocialCard.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @social_cards }
end
end

# GET /social_cards/1
# GET /social_cards/1.xml
def show
@social_card = SocialCard.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @social_card }
end
end

# GET /social_cards/new
# GET /social_cards/new.xml
def new
#@social_card = SocialCard.new

session[:social_card_params] ||= {}
@social_card=SocialCard.new(session[:social_card_params])
@social_card.current_step=session[:social_card_step]

#respond_to do |format|
# format.html # new.html.erb
#format.xml { render :xml => @social_card }
# end
end

# GET /social_cards/1/edit
def edit
@social_card = SocialCard.find(params[:id])
end

# POST /social_cards
# POST /social_cards.xml
def create
session[:social_card_params].deep_merge!(params[:social_card]) if params[:social_card]
@social_card = SocialCard.new(session[:social_card_params])
@social_card.current_step = session[:social_card_step]
if @social_card.valid?
if params[:back_button]
@social_card.previous_step
elsif @social_card.last_step?
@social_card.save if @social_card.all_valid?
else
@social_card.next_step
end
session[:social_card_step] = @social_card.current_step
end
if @social_card.new_record?
1.times {@social_card.helps.build}
render "new"
else
session[:social_card_step] = session[:social_card_params] = nil
flash[:notice] = "Ficha Social Creada Con Exito!"
redirect_to @social_card
end
end
#@social_card = SocialCard.new(params[:social_card])

#respond_to do |format|
# if @social_card.save
# format.html { redirect_to(@social_card, :notice => 'La Ficha Social Fue Creada Exitosamente.') }
# format.xml { render :xml => @social_card, :status => :created, :location => @social_card }
#else
# format.html { render :action => "new" }
#format.xml { render :xml => @social_card.errors, :status => :unprocessable_entity }
#end
#end
#end

# PUT /social_cards/1
# PUT /social_cards/1.xml
def update
@social_card = SocialCard.find(params[:id])

respond_to do |format|
if @social_card.update_attributes(params[:social_card])
format.html { redirect_to(@social_card, :notice => 'La Ficha Social Fue Modificada Exitosamente.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @social_card.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /social_cards/1
# DELETE /social_cards/1.xml
def destroy
@social_card = SocialCard.find(params[:id])
@social_card.destroy

respond_to do |format|
format.html { redirect_to(social_cards_url) }
format.xml { head :ok }
end
end
end


y bueno esto funcaba hasta que tuve que colocar la relacion :S sigue funcnado el multi steps pero cuando creo intento crear la parte de la relacion no funciona... por lo que creo que la parte de Session es quie no capta las cosas del help :S

Ayuda

Etiquetas: forms, relaciones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:15.