As in Rails as Tony said I use in my apps this kind of code:
def new
@model = Model.new
render
end
def create
@model = Model.new(params[model])
begin
@model.save
redirect url(:next), :message => {:success => 'You did it!'}
rescue Sequel::ValidationFailed
render :new
end
end
In new you can have:
<%= error_messages_for :model %>
..
..
On Oct 23, 9:28 pm, Tony Collen <[email protected]> wrote:
> Just like Rails... render the "new" action with whatever @model ivar set.
> If you redirect you have to put the model in the session, but redirecting
> would mess with the back button.
>
> - T
>
> On Fri, Oct 23, 2009 at 10:50 AM, Chris Hoeppner
> <[email protected]>wrote:
>
>
>
>
>
> > Hey,
>
> > I've been pondering about this for a while, or at least the best way to
> > achieve this. It's a fairly common thing, but I can't seem to wrap my
> > head around it for whatever reason.
>
> > So, say a user submits a form, and whatever he sent you is "invalid".
> > What next?
>
> > * Need to redirect somewhere else. Maybe back to the "new" form?
> > * Need to have the invalid object available, to show pertinent
> > validation messages. Do I put the object in the session and have the
> > "new" action try to read it from there?
> > * Maybe I don't want to have a big red box on top showing all the error
> > messages. Any "easy" way to display a field's error message next to the
> > field itself?
>
> > Any tips in this regard are greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" 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/merb?hl=en
-~----------~----~----~----~------~----~------~--~---