Sha256: 1eab22ce102e9ca7a5ecdd175d838b6666efd0e735f28c2741a3fa4f73a4abd8

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

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

  def index
    render :index, locals: { users: rom.relation(:users).as(:users) }
  end

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

  def new
    render :new, locals: { user: NewUserForm.build }
  end

  def create
    user_form = NewUserForm.build(params[:user]).save

    if user_form.success?
      redirect_to :users
    else
      render :new, locals: { user: user_form }
    end
  end

  def edit
    user_form = UpdateUserForm.build({}, { id: params[:id] })

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

  def update
    user_form = UpdateUserForm.build(params[:user], id: params[:id]).save

    if user_form.success?
      redirect_to :users
    else
      render :edit, locals: { user: user_form }
    end
  end

  def ping
    head :ok
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-rails-0.3.0 spec/dummy/app/controllers/users_controller.rb
rom-rails-0.3.0.rc1 spec/dummy/app/controllers/users_controller.rb