class UsersController
Public Instance Methods
create()
click to toggle source
POST /users POST /users.json
# File lib/r4/template/app/controllers/users_controller.rb, line 55 def create @user = User.new(user_params) respond_to do |format| if @user.save format.html { redirect_to users_url, notice: 'Uživatel byl uložen.' } format.json { render :show, status: :created, location: @user } else format.html { render :new } format.json { render json: @user.errors, status: :unprocessable_entity } end end end
destroy()
click to toggle source
DELETE /users/1 DELETE /users/1.json
# File lib/r4/template/app/controllers/users_controller.rb, line 85 def destroy @user.destroy respond_to do |format| format.html { redirect_to users_url, notice: 'Uživatel byl odstraněn.' } format.json { head :no_content } end end
edit()
click to toggle source
GET /users/1/edit
# File lib/r4/template/app/controllers/users_controller.rb, line 22 def edit end
edit_own_password()
click to toggle source
# File lib/r4/template/app/controllers/users_controller.rb, line 30 def edit_own_password @user = current_user render 'edit_password' end
edit_password()
click to toggle source
# File lib/r4/template/app/controllers/users_controller.rb, line 26 def edit_password @user = User.find(params[:id]) end
index()
click to toggle source
GET /users GET /users.json
# File lib/r4/template/app/controllers/users_controller.rb, line 7 def index @users = User.all end
new()
click to toggle source
GET /users/new
# File lib/r4/template/app/controllers/users_controller.rb, line 17 def new @user = User.new end
show()
click to toggle source
GET /users/1 GET /users/1.json
# File lib/r4/template/app/controllers/users_controller.rb, line 13 def show end
update()
click to toggle source
PATCH/PUT /users/1 PATCH/PUT /users/1.json
# File lib/r4/template/app/controllers/users_controller.rb, line 71 def update respond_to do |format| if @user.update(user_params) format.html { redirect_to users_url, notice: 'Uživatel byl upraven.' } format.json { render :show, status: :ok, location: @user } else format.html { render :edit } format.json { render json: @user.errors, status: :unprocessable_entity } end end end
update_password()
click to toggle source
# File lib/r4/template/app/controllers/users_controller.rb, line 35 def update_password @user = User.find(params[:id]) if @user.id == current_user.id if @user.update_with_password(user_params) sign_in @user, :bypass => true redirect_to root_path else render 'edit_password' end else if @user.update(user_params) redirect_to root_path else render 'edit_password' end end end
Private Instance Methods
set_user()
click to toggle source
Use callbacks to share common setup or constraints between actions.
# File lib/r4/template/app/controllers/users_controller.rb, line 95 def set_user @user = User.find(params[:id]) end
user_params()
click to toggle source
Never trust parameters from the scary internet, only allow the white list through.
# File lib/r4/template/app/controllers/users_controller.rb, line 102 def user_params params.required(:user).permit(:password, :password_confirmation, :current_password, :email, :login, :firstname, :lastname) end