Skip to content

Instantly share code, notes, and snippets.

@jhulford
Created January 23, 2013 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhulford/4611490 to your computer and use it in GitHub Desktop.
Save jhulford/4611490 to your computer and use it in GitHub Desktop.
def create
@user_session = UserSession.new(params[:user_session])
respond_to do |format|
if @user_session.save
add_flash :notices, "Login successful."
c = @user_session.user
if @user_session.user.host_with_port.nil?
@user_session.user.host_with_port = request.host_with_port
@user_session.user.save
end
History.create({:history_type => 'login', :user_id => c.id, :company_id => c.company_id})
format.html { redirect_back_or_default(:root) }
format.xml { render :xml => @user_session, :status => :created, :location => @user_session }
format.json { render :json => {"valid"=>true} }
else
errors_to_flash @user_session, :now => true
format.html { render :action => "new" }
format.xml { render :xml => @user_session.errors, :status => :unprocessable_entity }
format.json { render :json => {"errors"=>@user_session.errors.full_messages}}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment