That does make sense, and doesn't mess with the browsing history (aka
backbutton mess).
As for the error messages, I remember from Django (let's forget for a
moment that it's completely different from anything you have in Ruby)
you could really easily create your own "helper" for rendering form
fields, and could thus implement a generic way of showing error messages
next to the corresponding field in the form. Maybe there's something
half way similar in Merb? I guess I could wrap merb's form helper
methods, but that seems hacky.
The output I eventually want to obtain would be something along the
lines of...
<form....>
<p>
<label...>
<input .....>
<!-- if @model.errors['whatever'] -->
<p class="error">Field can't be empty</p>
</p>
</form>
I guess this might not be as common as to deserve a core helper, but
maybe I'm overlooking something?
Pavel Kunc escribió:
> 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
-~----------~----~----~----~------~----~------~--~---