Ruby on Rails Wednesday, November 12, 2014

I don't know why people are generally so unhelpful on these message
boards. I've been a professional programmer for years, and I've seen so
many people turned away because people just say "go read an entire book
for this one simple problem" rather than helping new users along.

Anyway, this question is very old, but here is a solution for anyone
that wants to learn.

Instead of using 'redirect_to' on invalid data, you can use 'render'.

Here is an example with a blog.

@blog= Blog.create(blog_params)
if @blog.valid?
redirect_to workshops_path
else
render '/blog/new' # or whatever view you're using
end

That's it. For the next person, no need to read an entire tutorial.
Hopefully this helps someone new build something great.

--
Posted via http://www.ruby-forum.com/.

--
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/756d20c873261ac55f4d7b2e1717555a%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment