module Orchestrate::Rails::UserGuide::TheController

The controller

Remember that the application is responsible for initializing the value of the id attribute when calling Model::create or Model::create! . In this example, the helper method primary_key provides a simple mechanism for doing so by requiring that the input params include my_primary_key.

Example controller: <rails-root>/app/controllers/my_things_controller.rb

class MyThingsController < ApplicationController

  def index
    @stuff = MyThing.all
  end

  def new
    @thing = MyThing.new
  end

  def create
    @thing = MyThing.create! attributes
  end

  def show
    @thing = MyThing.find params[:id]
  end

  def search
    @stuff = MyThing.search_results params[:query_str]
  end

  private
    def primary_key
      params[:my_thing][:my_primary_key]
    end

    def attributes
      params[:my_thing].merge(:id => primary_key)
    end
end

Next

The ref table