Sha256: 540a32083e0b7417596cfb736ed09b1f57ab5b4da91352202fd09681ab894629

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

# config
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')

module ActionArgsTestApp
  class Application < Rails::Application
    config.secret_token = [*'A'..'z'].join
    config.session_store :cookie_store, :key => '_myapp_session'
    config.active_support.deprecation = :log
    config.eager_load = false
  end
end
ActionArgsTestApp::Application.initialize!

# routes
ActionArgsTestApp::Application.routes.draw do
  resources :authors
  resources :books
  resources :stores
end

# models
class Author < ActiveRecord::Base
end
class Book < ActiveRecord::Base
end
class Store < ActiveRecord::Base
end

# helpers
module ApplicationHelper; end

# controllers
class ApplicationController < ActionController::Base
end
class AuthorsController < ApplicationController
  def show
    @author = Author.find params[:id]
    render text: @author.name
  end
end
class BooksController < ApplicationController
  # optional parameter
  def index(page = 1, q = nil)
    @books = Book.limit(10).offset(([page.to_i - 1, 0].max) * 10)
    @books = @books.where('title like ?', "%#{q}%") unless q.blank?
    render text: 'index'
  end

  def show(id)
    @book = Book.find(id)
    render text: @book.title
  end

  def create(book)
    book = book.permit :title, :price if Rails::VERSION::MAJOR >= 4
    @book = Book.create! book
    render text: @book.title
  end
end
if Rails::VERSION::MAJOR >= 4
  class StoresController < ApplicationController
    permits :name, :url

    def show(id)
      @store = Store.find(id)
      render text: @store.name
    end

    def create(store)
      @store = Store.create! store
      render text: @store.name
    end
  end
end

# migrations
class CreateAllTables < ActiveRecord::Migration
  def self.up
    create_table(:authors) {|t| t.string :name}
    create_table(:books) {|t| t.string :title; t.integer :price}
    create_table(:stores) {|t| t.string :name; t.string :url}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
action_args-1.0.4 spec/fake_app.rb
action_args-1.0.3 spec/fake_app.rb
action_args-1.0.2 spec/fake_app.rb