Message validation #48

Closed
RKushnir opened this Issue May 6, 2012 · 9 comments

Projects

None yet

6 participants

@RKushnir

Hi,
currently when you use send_message there's no way to get the list of errors if it fails. I would like to tell user that he forgot to specify the recipient, for example. Maybe, it's better to split this function to allow the following:

@message = user.compose_message(params)
if @message.deliver
  redirect_to :sentbox
else
  render :new
end
@Roendal
mailboxer member

The errors are not stored in Message but in Receipt. You can see something similar to what you want here

    @receipt = @actor.send_message(@recipients, params[:body], params[:subject])
    if (@receipt.errors.blank?)
      @conversation = @receipt.conversation
      flash[:success]= t('mailboxer.sent')
      redirect_to conversation_path(@conversation, :box => :sentbox)
    else
      render :action => :new
    end

Does this help you?

@RKushnir

I see, thanks. But how to render these errors on the form?
The usual way is to build a message @message = Message.new in controller new action, and then use form_for @message. And in case of failure on create we could just render the same @message object with errors. If we have @receipt instead, some special handling is required to display the errors. What do you think?

@Roendal
mailboxer member

Here you can see the form we use in SocialStream.

You are totally right. Some special handling is required. Maybe it could be really improved, but I can't take a deeper look at it. If you have any ideas on how to make it easier, we can discuss it ;)

@daveworth

@Roendal, this would be a great addition to either the README or the Wiki. If you'd like it added to the README I volunteer and will happily do so. I have to do exactly this and didn't see a good explanation until working through the issues.

@Roendal
mailboxer member

I did this tutorial (linked from the README) https://github.com/ging/mailboxer/wiki/GUI-Example-on-a-real-application, but this point is not really highlighted (there is a link at the bottom to the folder with the form view).

If yout think making a bigger comment in this tutorial, creating a new one (and linking it from the README) or even a section in the README will help other developers I will gladly accept any new documentation :)

@daveworth

@Roendal, I think documentation is always best when explicit. You can't force your users to read (and I'm often guilty of this.. I just want the code) but having it there is always best. I will happily help contribute to the documentation as I like writing it. Let's chat through how to do this!

@Roendal
mailboxer member

I think the best way to add this info is improving https://github.com/ging/mailboxer/wiki/GUI-Example-on-a-real-application as it is a GUI related problem.

@davidstosik

Hello,
It seems I'm pulling this issue from the limbo, but I'm facing the same problems...

I want to validate a message in order to avoid invalid record errors. Updating to 0.13.0 allowed me to check the Receipt object returned by #send_message. I can even use receipt.errors to display the error messages in my new message form, as suggested by @Roendal above, but the messages are not "perfect", as they say stuff like "Notification subject can't be blank". I'd rather have those messages say "Message subject can't be blank".
Also, as I'm using #form_tag to build the form markup, it gets difficult to highlight erroring fields.

Is my best solution to use #form_for on a stub Message object that I'll use only for error handling?

Any other suggestion?

@deivid-rodriguez

This is now handled differently than before. I'd close this and handle any issues that come up with the behavior separately.

@jcoyne jcoyne closed this Jul 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment