On 26 June 2013 02:55, Cameron Gilroy <m...@camerongilroy.com> wrote:
> Here is an update, I have it working as only a group or as only a non-group
> user. I have below the create controller and was wondering what would be the
> best way to allow associations and non-associated records. Thanks
>
>   def create
>     if Group.nil?

Can you explain what the above line is for?

Colin

>       @group = Group.find(params[:group_id])
>       @user = @group.users.create(params[:user])
>     else
>       @user = User.new
>       @user.ip_address = request.remote_ip
>       @user.ua_string = request.user_agent
>       @user = User.new(params[:user])
>     end
>
>     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
>     end
>   end

-- 
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+unsubscr...@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%3D0gLszNroLRpSmokgNqQdGDU7m%2BZ6PuSh-izqVDqtZ3%3DpUmg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to