On Tue, Jun 25, 2013 at 9:55 PM, Cameron Gilroy <
m...@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).