Multiple Forms and Multiple tables +One Model +One Controller


#1

Hi
Im using Multiple Forms and Multiple tables +One Model +One Controller
in my
rails application and give example code Please help me

Thanks & Regards
Balaji


#2

???
maybe I missed the details in some other post,
but I have no idea, what exactly you want.
please be more specific, otherwise nobody will be able
to help you.


#3

I do not really understand, what you are doing here, but:

You are using “else if” without a condition several times,
beneath the fact that the correct ruby syntax is elsif

Then Ruby would interpret the following line:
@stage = params[:stage].to_i
as condition and the outcome of this is most likely not
what you would expect.

And all those "end’ show too, that the structure is a bit weird.

I think, what you want to do would need something like this:

def wizard
if params[:stage].nil?

elsif params[:stage].to_i == 1

elsif params[:stage].to_i == 2

else

end
render :template => ‘wizard\stage’+@next_stage.to_s
end


#4

Hi
Im using Multiple Forms and Multiple tables +One Model +One Controller
in my
rails application

I have 5 forms(5 stages) to create my rails application.

1st form: to enter the data and click the next button.To get the values
in
session.
2nd form: to enter the data and click the next button.To get the values
in
session.
3rd form: to enter the data and click the next button.To get the values
in
session.
4th form: to enter the data and click the next button.To get the values
in
session.
5th form: to enter the data and click the create button.To store the
data to
corresponding table.

Controller code:

class WizardController < ApplicationController

def wizard
if params[:stage].nil?
@stage = 1
@resort_basic = ResortBasic.new {}

@resort_basic.resortclassid=params[:resortclass][:resortclassid]
@resort_basic.resortname=params[:resortname]
@resort_basic.website=params[:website]

@resort_basic.save()

session[:resort_basicObj] = @resort_basic # Or whatever model is
storing
your stuff

else if

 @stage = params[:stage].to_i
 @dummyObj = session[:resort_basicObj]

 @dummyObj.save()


 @resort_contactdetail = ResortContactdetail.new{}

 @resort_contactdetail.resortid=@dummyObj.id

 @resort_contactdetail.firstname= params[:firstname]
 @resort_contactdetail.lastname= params[:lastname]
 @resort_contactdetail.designation= params[:designation]

# @resort_contactdetail.save()

session[:resort_contactdetailObj] = @resort_contactdetail

else if

 @stage = params[:stage].to_i
 @dummyObj1 = session[:resort_contactdetailObj]

 @dummyObj1.save()

 @resort_address = ResortAddress.new{}

 @resort_address.resortid=@dummyObj1.id

 @resort_address.street= params[:street]
@resort_address.area= params[:area]
   @resort_address.countryid= params[:country][:countryid]
 @resort_address.pincode= params[:pincode]

# @resort_address.save()

session[:resort_addressObj] = @resort_address

else if

 @stage = params[:stage].to_i
 @dummyObj2 = session[:resort_addressObj]

 @dummyObj2.save()

 @resort_additionaldetail = ResortAddtionaldetail.new{}

 @resort_additionaldetail.resortid=@dummyObj2.id

 @resort_additionaldetail.aminity= params[:aminity]
     @resort_additionaldetail.pickupoffered= params[:pickupoffered]
 @resort_additionaldetail.email_id= params[:email_id]


 #@resort_additionaldetail.save()

session[:resort_additionaldetailObj] = @resort_additionaldetail

else

 @stage = params[:stage].to_i
 @dummyObj3 = session[:resort_additionaldetailObj]

 @dummyObj3.save()

 @resort_accomodation = ResortAccomodation.new{}

 @resort_accomodation.resortid=@dummyObj3.id

 @resort_accomodation.roomtypeid= params[:roomtype][:roomtypeid]
     @resort_accomodation.numberofrooms= params[:numberofrooms]
 @resort_accomodation.availablerooms= params[:availablerooms]

@resort_basic.save()
@resort_contactdetail.save()
@resort_address.save()
@resort_additionaldetail.save()
@resort_accomodation.save()

end

@next_stage = @stage + 1

#@wizard_data = session[:wizard_data]

render :template => ‘wizard\stage’+@next_stage.to_s
end
end
end
end
end

I enter the data in 1st form and to click the next button.

I got error:
Template is missing

Missing template wizard/wizard.html.erb in view path
D:/RubyProjects/TestEcohols/app/views

but im using stage1.html.erb to stage2.html.erb.

Please help me…
Thanks & Regards
Balaji


#5

Hi Thorsten Müller
i got bugs:
NoMethodError in WizardController#wizard

You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

Please help me.

Thanks and Regards

Balaji


#6

Hi Thorsten Müller

your guideness very helpful for me. i used the code but i got bugs.

code

class WizardController < ApplicationController

def wizard
if params[:stage].nil?
@stage = 1
@resort_basic = ResortBasic.new {}

@resort_basic.resortclassid=params[:resortclass][:resortclassid]
@resort_basic.resortname=params[:resortname]
@resort_basic.resorttypeid=params[:resorttype][:resorttypeid]
@resort_basic.seasonid=params[:seasontype][:seasontypeid]
@resort_basic.website=params[:website]

@resort_basic.save()

session[:resort_basicObj] = @resort_basic # Or whatever model is
storing
your stuff

elsif params[:stage].to_i ==1

# @stage = params[:stage].to_i==1
 @dummyObj = session[:resort_basicObj]

# @dummyObj.save()


 @resort_contactdetail = ResortContactdetail.new{}

 @resort_contactdetail.resortid=@dummyObj.id

 @resort_contactdetail.firstname= params[:firstname]
 @resort_contactdetail.lastname= params[:lastname]
 @resort_contactdetail.designation= params[:designation]
 @resort_contactdetail.email_id= params[:email_id]
 @resort_contactdetail.mobile= params[:mobile]
 @resort_contactdetail.telephone1= params[:telephone1]
 @resort_contactdetail.telephone2= params[:telephone2]
 @resort_contactdetail.fax= params[:fax]

# @resort_contactdetail.save()

session[:resort_contactdetailObj] = @resort_contactdetail

elsif params[:stage].to_i ==2

# @stage = params[:stage].to_i ==2
 @dummyObj1 = session[:resort_contactdetailObj]

@dummyObj1.save()

 @resort_address = ResortAddress.new{}

# @resort_address.resortid=@dummyObj1.id

 @resort_address.street= params[:street]
 @resort_address.area= params[:area]
 @resort_address.districtid= params[:district][:districtid]
 @resort_address.cityid= params[:city][:cityid]
 @resort_address.stateid= params[:state][:stateid]
 @resort_address.countryid= params[:country][:countryid]
 @resort_address.pincode= params[:pincode]

# @resort_address.save()

session[:resort_addressObj] = @resort_address

elsif params[:stage].to_i ==3

# @stage = params[:stage].to_i ==3
# @dummyObj2 = session[:resort_addressObj]

# @dummyObj2.save()

 @resort_additionaldetail = ResortAddtionaldetail.new{}

# @resort_additionaldetail.resortid=@dummyObj2.id

 @resort_additionaldetail.aminity= params[:aminity]
 @resort_additionaldetail.directions= params[:directions]
 @resort_additionaldetail.transport= params[:transport]
 @resort_additionaldetail.map= params[:map]
 @resort_additionaldetail.pickupoffered= params[:pickupoffered]
 @resort_additionaldetail.email_id= params[:email_id]


 #@resort_additionaldetail.save()

session[:resort_additionaldetailObj] = @resort_additionaldetail

else params[:stage].to_i ==4

# @dummyObj3 = session[:resort_additionaldetailObj]

# @dummyObj3.save()

 @resort_accomodation = ResortAccomodation.new{}

# @resort_accomodation.resortid=@dummyObj3.id

 @resort_accomodation.roomtypeid= params[:roomtype][:roomtypeid]
 @resort_accomodation.singleoccupancyrate= 

params[:singleoccupancyrate]
@resort_accomodation.doubleoccupancyrate=
params[:doubleoccupancyrate]
@resort_accomodation.extrapersoncost= params[:extrapersoncost]
@resort_accomodation.numberofrooms= params[:numberofrooms]
@resort_accomodation.availablerooms= params[:availablerooms]

 @resort_basic.save()
 @resort_contactdetail.save()
 @resort_address.save()
 @resort_additionaldetail.save()
 @resort_accomodation.save()

end

@next_stage = @stage + 1

#@wizard_data = session[:wizard_data]

render :template => ‘wizard\stage’+@next_stage.to_s
end
end
I have 5 forms(5 stages) to create my rails application.

1st form: to enter the data and click the next button.To get the values
in
session.
2nd form: to enter the data and click the next button.To get the values
in
session.
3rd form: to enter the data and click the next button.To get the values
in
session.
4th form: to enter the data and click the next button.To get the values
in
session.
5th form: to enter the data and click the create button.To store the
data to
corresponding table.

i used the code and not stored the value in database.im only doing this
rails project.
Please help me.

Thanks and Regards

Balaji


#7

Hi Thorsten Müller

I have 5 forms(5 stages) to create my rails application.

1st form: to enter the data and click the next button.To get the values
in
session.
2nd form: to enter the data and click the next button.To get the values
in
session.
3rd form: to enter the data and click the next button.To get the values
in
session.
4th form: to enter the data and click the next button.To get the values
in
session.
5th form: to enter the data and click the create button.To store the
data to
corresponding table.

controller code

class WizardController < ApplicationController

def wizard
if params[:stage].nil?
@stage = 1
@resort_basic = ResortBasic.new {}

@resort_basic.resortclassid=params[:resortclass][:resortclassid]
@resort_basic.resortname=params[:resortname]
@resort_basic.resorttypeid=params[:resorttype][:resorttypeid]
@resort_basic.seasonid=params[:seasontype][:seasontypeid]
@resort_basic.website=params[:website]

@resort_basic.save()

session[:resort_basicObj] = @resort_basic # Or whatever model is
storing
your stuff

elsif
#params[:stage].to_i ==1

 @stage = params[:stage].to_i
# @dummyObj = session[:resort_basicObj]

# @dummyObj.save()


 @resort_contactdetail = ResortContactdetail.new{}

# @resort_contactdetail.resortid=@dummyObj.id

 @resort_contactdetail.firstname= params[:firstname]
 @resort_contactdetail.lastname= params[:lastname]
 @resort_contactdetail.designation= params[:designation]
 @resort_contactdetail.email_id= params[:email_id]
 @resort_contactdetail.mobile= params[:mobile]
 @resort_contactdetail.telephone1= params[:telephone1]
 @resort_contactdetail.telephone2= params[:telephone2]
 @resort_contactdetail.fax= params[:fax]

 #@resort_contactdetail.save()

session[:resort_contactdetailObj] = @resort_contactdetail

elsif
#params[:stage].to_i ==2

 @stage = params[:stage].to_i
# @dummyObj1 = session[:resort_contactdetailObj]

@dummyObj1.save()

 @resort_address = ResortAddress.new{}

# @resort_address.resortid=@dummyObj1.id

 @resort_address.street= params[:street]
 @resort_address.area= params[:area]
 @resort_address.cityid= params[:city][:cityid]
 @resort_address.districtid= params[:district][:districtid]
 @resort_address.stateid= params[:state][:stateid]
 @resort_address.countryid= params[:country][:countryid]
 @resort_address.pincode= params[:pincode]

# @resort_address.save()

session[:resort_addressObj] = @resort_address

elsif
#params[:stage].to_i ==3

 @stage = params[:stage].to_i
# @dummyObj2 = session[:resort_addressObj]

# @dummyObj2.save()

 @resort_additionaldetail = ResortAddtionaldetail.new{}

 #@resort_additionaldetail.resortid=@dummyObj2.id

 @resort_additionaldetail.aminity= params[:aminity]
 @resort_additionaldetail.directions= params[:directions]
 @resort_additionaldetail.transport= params[:transport]
 @resort_additionaldetail.map= params[:map]
 @resort_additionaldetail.pickupoffered= params[:pickupoffered]
 @resort_additionaldetail.email_id= params[:email_id]


# @resort_additionaldetail.save()

session[:resort_additionaldetailObj] = @resort_additionaldetail

else
@stage=params[:stage].to_i

# @dummyObj3 = session[:resort_additionaldetailObj]

 #@dummyObj3.save()

 @resort_accomodation = ResortAccomodation.new{}

 #@resort_accomodation.resortid=@dummyObj3.id

 @resort_accomodation.roomtypeid= params[:roomtype][:roomtypeid]
 @resort_accomodation.singleoccupancyrate= 

params[:singleoccupancyrate]
@resort_accomodation.doubleoccupancyrate=
params[:doubleoccupancyrate]
@resort_accomodation.extrapersoncost= params[:extrapersoncost]
@resort_accomodation.numberofrooms= params[:numberofrooms]
@resort_accomodation.availablerooms= params[:availablerooms]

end

@resort_basic.save()

@resort_contactdetail.save()

@resort_address.save()

@resort_additionaldetail.save()

@resort_accomodation.save()

@next_stage = @stage+1

#@wizard_data = session[:wizard_data]

render :template => ‘wizard\stage’+@next_stage.to_s
end
end

I enter the values in 5 forms but values not store corresponding table
in
database.
please give me any suggestions.

Thanks
Balaji


#8

*Hi Thorsten Müller *
In my rails application, im using five forms to save the corresponding
5
tables and 1st form using next button to 4th form.final form using
create
button.To click the create button to save the values in databases.

  • please give any idea… i can’t understand the bugs*

Please help me…

Thanks
balaji


#9

*Hi Thorsten Müller *
In my rails application, im using five forms to save the corresponding
5
tables and 1st form using next button to 4th form.final form using
create
button.To click the create button to save the values in databases.

  • please give any idea… i can’t understand the bugs*

Please help me…

Thanks
balaji


#10

Hi
i use various forms and one controller.

view code

<% form_tag :action => ‘wizard’, :stage => @next_stage do %>

controller code:

def wizard
if params[:stage].nil?

elsif params[:stage].to_i == 1

elsif params[:stage].to_i == 2

elsif params[:stage].to_i == 3

elsif params[:stage].to_i == 4

else

end
render :template => ‘wizard\stage’+@next_stage.to_s
end

but i got error and first form values only saved in databases

so please help me
Thanks
balaji


#11

On 05 Dec 2008, at 09:00, balaji rajagopal wrote:

i use various forms and one controller.

view code

<% form_tag :action => ‘wizard’, :stage => @next_stage do %>



elsif params[:stage].to_i == 4

else

end

If you see the above, you should seriously start thinking about giving
up Ruby and going back to Applesoft BASIC. And even that would be
insulting BASIC in a way.

render :template => ‘wizard\stage’+@next_stage.to_s
end

Why the double backslashes and where does that instance variable come
out of all of a sudden? ‘wizard/stage’+params[:stage]


I’m really sorry to say, but your code has more wrong to it than right.

You could also check out acts_as_wizard:
http://github.com/Adkron/actsaswizard/tree/master

Best regards

Peter De Berdt


#12

On 05 Dec 2008, at 11:21, balaji rajagopal wrote:

I follow ur way and i used the above code but i got the bugs

can't convert nil into String

Well, if an application gives you an error, it usually wants to say
something. In this case it expected a string, and got a nil. You
didn’t include what line it choked on, but I guess it’s the render
one. It’s telling you that params[:stage] is nil, so you need to
handle that.

‘wizard/stage’+(params[:stage] || ‘’)

And please please please, do yourself a favor, read some books on
Rails first. There are some nice ones out there and most of them have
a nice introduction to basic programming principles. Your code is just
completely unmaintainable.

Best regards

Peter De Berdt


#13

Hi
i am new to rails…
can u explain me how do i store data into multiple table from one
form.Explain me with sample code
Also Explain me about association between tables…i studied many
articles .but stil i am confuse.

pls help me

Thanks

Durga


#14

Hi

I follow ur way and i used the above code but i got the bugs

can't convert nil into String

code

class WizardController < ApplicationController

def wizard

if params[:stage].nil?
# @stage = 1
@resort_basic = ResortBasic.new {}

@resort_basic.resortclassid=params[:resortclass][:resortclassid]
@resort_basic.resortname=params[:resortname]
@resort_basic.resorttypeid=params[:resorttype][:resorttypeid]
@resort_basic.seasonid=params[:seasontype][:seasontypeid]
@resort_basic.website=params[:website]

@resort_basic.save()

session[:resort_basicObj] = @resort_basic # Or whatever model is

storing
your stuff

elsif
params[:stage].to_i ==1

# @stage = params[:stage].to_i
# @dummyObj = session[:resort_basicObj]

# @dummyObj.save()


 @resort_contactdetail = ResortContactdetail.new{}

# @resort_contactdetail.resortid=@dummyObj.id

 @resort_contactdetail.firstname= params[:firstname]
 @resort_contactdetail.lastname= params[:lastname]
 @resort_contactdetail.designation= params[:designation]
 @resort_contactdetail.email_id= params[:email_id]
 @resort_contactdetail.mobile= params[:mobile]
 @resort_contactdetail.telephone1= params[:telephone1]
 @resort_contactdetail.telephone2= params[:telephone2]
 @resort_contactdetail.fax= params[:fax]

 @resort_contactdetail.save()

session[:resort_contactdetailObj] = @resort_contactdetail

elsif
params[:stage].to_i ==2

# @stage = params[:stage].to_i
# @dummyObj1 = session[:resort_contactdetailObj]

@dummyObj1.save()

 @resort_address = ResortAddress.new{}

# @resort_address.resortid=@dummyObj1.id

 @resort_address.street= params[:street]
 @resort_address.area= params[:area]
 @resort_address.cityid= params[:city][:cityid]
 @resort_address.districtid= params[:district][:districtid]
 @resort_address.stateid= params[:state][:stateid]
 @resort_address.countryid= params[:country][:countryid]
 @resort_address.pincode= params[:pincode]

 @resort_address.save()

session[:resort_addressObj] = @resort_address

elsif
params[:stage].to_i ==3

# @stage = params[:stage].to_i
# @dummyObj2 = session[:resort_addressObj]

# @dummyObj2.save()

 @resort_additionaldetail = ResortAddtionaldetail.new{}

 #@resort_additionaldetail.resortid=@dummyObj2.id

 @resort_additionaldetail.aminity=params[:aminity]
 @resort_additionaldetail.directions=params[:directions]
 @resort_additionaldetail.transport=params[:transport]
 @resort_additionaldetail.map=params[:map]
 @resort_additionaldetail.pickupoffered= params[:pickupoffered]
 @resort_additionaldetail.email_id= params[:email_id]


@resort_additionaldetail.save()

#session[:resort_additionaldetailObj] = @resort_additionaldetail

else params[:stage].to_i==4

@stage=params[:stage].to_i

# @dummyObj3 = session[:resort_additionaldetailObj]

 #@dummyObj3.save()

 @resort_accomodation = ResortAccomodation.new{}

 #@resort_accomodation.resortid=@dummyObj3.id

 @resort_accomodation.roomtypeid= params[:roomtype][:roomtypeid]
 @resort_accomodation.singleoccupancyrate= 

params[:singleoccupancyrate]
@resort_accomodation.doubleoccupancyrate=
params[:doubleoccupancyrate]
@resort_accomodation.extrapersoncost= params[:extrapersoncost]
@resort_accomodation.numberofrooms= params[:numberofrooms]
@resort_accomodation.availablerooms= params[:availablerooms]

  @resort_accomodation.save()

end

@next_stage = @stage+1

#@wizard_data = session[:wizard_data]

render :template => ‘wizard\stage’+@next_stage.to_s

render :template => ‘wizard/stage’+params[:stage]
end
end

please help me

Thanks

balaji