On Tue, Jun 25, 2013 at 9:55 PM, Cameron Gilroy <me@camerongilroy.com> wrote:
> respond_to do |format|
> if @user.save && @user.group_id == nil
> format.html { redirect_to "/", notice: 'Thank you for registering!'
> }
> elsif @user.save && @user.group_id != ""
> format.html { redirect_to group_path(@group.token), notice: 'Thank
> you for registering!' }
> else
> format.html { render action: "new" }
> format.json { render json: @user.errors, status:
> :unprocessable_entity }
> end
This will do (or at least try) the save twice, if the user has a
group. I'd recommend:
if it saves
redirect to (if it has a group, the group, else /)
else
give error msg
end
Also, look closely at the way you're checking for a group. The first
option will trigger if the group is nil, the second if it's not ""
(empty string)... but what if it *is* ""? That's neither nil nor
not-"", so it will take the "else" path and pretend like it didn't
save. I suggest you use .blank? (or its inverse, .present?) to tell
if it's there or not. Both nil and "" count as blank (and not
present).
-Dave
--
Dave Aronson, the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
taking contracts in or near NoVa or remote.
See information at http://www.Codosaur.us/.
--
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/CAHxKQiioC7s_WeL8f%3DOTp0Okfw7A5QsxAe%2BuMP6LkM5Kuc1CiA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment