Ruby on Rails Friday, February 10, 2017

On 10 February 2017 at 14:29, 'krfg' via Ruby on Rails: Talk
<rubyonrails-talk@googlegroups.com> wrote:
> ...
> Then the problem was just rendering the home page after invalid submission
> instead of redirecting to the home page.
> The original code was render 'static_pages/home', you can check it here.
> This original code would show a flash error message that the test would
> catch with:
>
> assert_select 'div#error_explanation'
>
> If I remove or comment this line in the test, the test would pass as long as
> I use a redirect in the create action of the microposts controller.
> No flash errors are showed after redirection, though

That is because the static_pages controller knows nothing about the
error. If you want to get that into the static_pages controller you
will have to do something like (untested)

redirect_to 'static_pages/home', :flash => { :error =>
@micropost.errors.full_messages.join(', ')}

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs_nP2c_7wWzJ5W8ufvOb6_d6bF7pvdyo-cNfTg0gbFCw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment