On Oct 17, 4:55 am, Andrew Porter <[EMAIL PROTECTED]> wrote:
> Jay Pangmi wrote:
>
> you specific problem here is -
>
> ...
>
> > rescue
> > redirect_to_booking("Invalid input.")
> > end
>
> You render here
>
> > if camp_loc.blank? || nights.blank? || parents.blank?
> > redirect_to_booking("Fields with '*' are required fields.")
> > elsif (nights.to_i > 2) || ((parents.to_i + children.to_i) > 8)
> > redirect_to_booking("Limitation: Maximum stay of 2 nights with group
> > of maximum 8 people.")
> > elsif children.nil? and family_rate_claim == "1"
> > redirect_to_booking("You are not eligible for claiming family
>
> And also here
>
> Do .
>
> return( redirect_to_booking("Invalid input.") )
>
> So your code doesn't fall through.
I think there's a relationship between the problem you are
experiencing and the face that you are performing validations in your
controller and not your model. As Rob said above, you should move the
validations:
> if camp_loc.blank? || nights.blank? || parents.blank?
> elsif (nights.to_i > 2) || ((parents.to_i + children.to_i) > 8)
> elsif children.nil? and family_rate_claim == "1"
to your model and use ActiveRecord validations:
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html
and
callbacks:
http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html
to implement the validations in your models
Then you could call save (or valid?) and use error_messages_for (vs.
flash) to display your messages. This is all in addition to calling
return with each render.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---