metamaps--metamaps/app/controllers/users_controller.rb

71 lines
1.5 KiB
Ruby
Raw Normal View History

2012-09-23 02:39:12 +00:00
class UsersController < ApplicationController
before_filter :require_no_user, only: [:new, :create]
before_filter :require_user, only: [:edit, :update]
2012-09-23 02:39:12 +00:00
respond_to :html, :json
2012-12-16 20:00:43 +00:00
autocomplete :user, :name, :full => true
2012-09-23 02:39:12 +00:00
# GET /user/new
def new
@user = User.new
respond_with(@user)
end
# GET /user/edit
def edit
@user = current_user
respond_with(@user)
end
# GET /user
def show
@user = User.find(params[:id])
2013-01-08 00:57:04 +00:00
@topics = @user.topics.order("created_at").limit(3)
@synapses = @user.synapses.order("created_at").limit(3)
@maps = @user.maps.order("created_at").limit(3)
2012-09-23 02:39:12 +00:00
2013-01-08 00:57:04 +00:00
respond_with(@user, @topics, @synapses, @maps)
2012-09-23 02:39:12 +00:00
end
# POST /user
def create
@session = Session.create(params[:user])
redirect_to(root_url) and return if @session.valid?
@user = User.create(params[:user])
#generate a random 8 letter/digit code that they can use to invite people
@user.code = rand(36**8).to_s(36)
2012-09-23 02:39:12 +00:00
@user.save
# direct them straight to the metamaps manual map.
@connor = User.find(555629996)
@map = Map.first(:conditions => [ "id = ?", 5])
2012-09-23 02:39:12 +00:00
if @map
respond_with(@user, location: user_map_url(@connor,@map)) do |format|
end
else
respond_with(@user, location: root_url) do |format|
end
2012-09-23 02:39:12 +00:00
end
end
# PUT /user
def update
@user = current_user
@user.attributes = params[:user]
@user.save
respond_with(@user, location: user_url(@user)) do |format|
2012-09-23 02:39:12 +00:00
end
end
end