Ruby on Rails Friday, February 10, 2017

On Friday, February 10, 2017 at 3:43:00 PM UTC+1, Colin Law wrote:
On 10 February 2017 at 14:29, 'krfg' via Ruby on Rails: Talk
<rubyonra...@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

It works, even though it needs some styling.
I am really grateful for your help Colin. and this is not the first time you helped me.
Many thanks indeed

--
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/545ed3a3-48b6-4a67-9f31-dd767f05b453%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment