Hi, I'm trying to validate couple of things in the controller as I
couldn't figure out how I can implement the same in the models. I'm
trying to check the 'children' field in the form and if its nil, it
checks the 'family claim' check box and if its ticked show error message
and if this is validated ok then checks that the sum of children and
parents field's values don't exceed 8. If everything's fine then do the
saving in the carts table. Here's how I've implemented it but doesn't do
the job for the combination of children and family claim field:
CONTROLLER:
def add_to_cart
if params[:children].nil?
if params[:family_claim]=="1"
return (redirect_to_booking("You can't claim for family rate
without children."))
end
else
if ((params[:parents].to_i) + (params[:children].to_i)) > 8
return (redirect_to_booking("Maximum 8 people in a group."))
end
end
if params[:family_claim] != "1"
total = (((params[:parents].to_i + params[:children].to_i) * 4.85)
* params[:nights].to_i)
else
total = (19.4 * params[:nights].to_i)
end
@cart=find_cart
carts=Cart.create(:campsite => params[:camp][:id], :arrival_date =>
params[:arrival_date],
:nights => params[:nights], :parents =>
params[:parents],
:children => params[:children], :family_claim =>
params[:family_claim],
:total => total)
if carts.save
@cart << carts.id
@cart_details = find_items_in_session
else
redirect_to_booking("Invalid input. Details couldn't be stored.
Please Try Again..")
end
end
Any suggestions.. thanks..
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---