Sha256: 38991780f43b9a7789dd441d2b1d47a84f86d57369c48d7888f68b7ae90bb664

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

class UsersController < ApplicationController
  rescue_from ROM::Rails::RelationParamsMissingError do
    head :bad_request
  end

  def index
    render :index, locals: { users: rom.relations[:users].map_with(:user) }
  end

  def search
    render :index, locals: {
      users: rom.relations[:users].map_with(:user).by_name(params[:name])
    }
  end

  def new
    render :new, locals: { user: UserForm.new }
  end

  def create
    user_form = UserForm.new(params[:user].permit!)

    if user_form.valid?
      rom.commands[:users].create.call(user_form.to_h)
      redirect_to :users
    else
      render :new, locals: { user: user_form }
    end
  end

  def edit
    data = rom.relations[:users].where(id: params[:id]).one
    user_form = UserForm.new(data)

    render :edit, locals: { user: user_form }
  end

  def update
    data = rom.relations[:users].where(id: params[:id]).one
    user_form = UserForm.new(data).merge(params[:user].permit!)

    if user_form.valid?
      rom.commands[:users].update.by_id(params[:id]).call(user_form.to_h)
      redirect_to :users
    else
      render :edit, locals: { user: user_form }
    end
  end

  def ping
    head :ok
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-rails-2.4.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-2.3.1 spec/dummy/app/controllers/users_controller.rb
rom-rails-2.3.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-2.2.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-2.0.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.2.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.1.1 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.1.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.0.1 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.0.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.0.0.rc1 spec/dummy/app/controllers/users_controller.rb
rom-rails-1.0.0.beta1 spec/dummy/app/controllers/users_controller.rb