I have a three part user signup that work with two separate models: User, and Customer Info. There's a user signup that I submit remotely, and it goes to the next part of the form. I want to be able to use the current_user
variable when I submit the Customer Info row. The following code works when I test without remote, but it just doesn't even create the row at all when I do it with the remote. Is there another variable I can use in lieu of this variable? Or is there a better way of accomplishing this?
def create
@customer_info = CustomerInfo.new(params[:customer_info].merge(:user_id => current_user.id))
respond_to do |format|
if @customer_info.save
format.html { redirect_to tasks_url, notice: 'Customer info was successfully created.' }
format.json { render json: tasks_url, status: :created, location: @customer_info }
else
format.html { render action: "new" }
format.json { render json: @customer_info.errors, status: :unprocessable_entity }
end
end
end
belongs_to
User, then it should have auser_id
attribute, and your merge should work. Are you sure it's getting called, AND thatcurrent_user.id
is the right value? Add a line likelogger.debug "current_user is #{current_user.inspect}"
to the beginning of the create method, then look indevelopment.log
to see what you get. I wonder if the create method is even getting called ... perhaps you need to specify the method as POST or something?<%= csrf_meta_tag %>
to your layout? Because if you do not have that then your user will probably be logged out when you useremote: true
because of RequestForgeryProtection