Ruby on Rails
Tuesday, June 25, 2013
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?
@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
On Monday, June 24, 2013 10:54:14 PM UTC+10, Cameron Gilroy wrote:
Hi--I'm working on a project that has users and groups, users can be members of a group or they can just be a user - what's going to be the best way to deal with this?I understand the normal has_many relationship just not sure how to do this one. Will try to post some code snippets tomorrow.Thanks, Cameron
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/db8099f1-e254-428d-9462-01174f13bda6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment