Sha256: 1c66b245113c6a8648726bf80279591ea9bbdbb95cf57bfbdb6faf75052d27db

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

# -*- encoding: utf-8 -*-
# -*- frozen_string_literal: true -*-
# -*- warn_indent: true -*-

class UsersController < ApplicationController

  before_action :find_user, except: [:index, :new, :create]

  def index
    @users = ::User.all
  end

  def new
    @user = ::User.new
  end

  def create
    @user = ::User.new(user_params)
    if @user.save
      redirect_to users_path
    else
      render :new, status: :unprocessable_entity
    end
  end

  def edit
  end

  def update
    if @user.update(user_params)
      redirect_to users_path
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @user.destroy
    redirect_to users_path
  end

  private

  def user_params
    params.require(:user).permit(
      :name,
      :email,
      :password,
      :mobile_number,
      :birth_date,
      :terms,
      :excellence,
      :blog_url,
      :fruit_id,
      :favorite_color,
      skill_ids: [],
      address_attributes: [
        :street,
        :state,
        :city,
        :postal_code,
        :country_id,
      ]
    )
  end

  def find_user
    @user = ::User.find(params.fetch(:id))
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rails_bootstrap_form-0.8.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.7.2 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.7.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.7.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.6.2 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.6.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.6.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.5.3 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.5.2 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.5.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.5.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.4.2 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.4.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.4.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.3.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.3.0 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.2.3 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.2.2 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.2.1 demo/app/controllers/users_controller.rb
rails_bootstrap_form-0.2.0 demo/app/controllers/users_controller.rb