Sha256: 8c89f44540bc9fc2c5e38a28e49f69689447686627119cebfb356f3c8b13a00c

Contents?: true

Size: 691 Bytes

Versions: 49

Compression:

Stored size: 691 Bytes

Contents

class CardsController < ApplicationController

  def index
    load_cards
  end

  def show
    load_cards
    load_card
  end

  def new
    load_cards
    build_card
  end

  def create
    load_cards
    build_card
    if @card.save
      redirect_to card_path(@card)
    else
      render 'new'
    end
  end

  private

  def card_scope
    Card.all
  end

  def load_cards
    @cards ||= card_scope.to_a
  end

  def load_card
    @card ||= card_scope.find(params[:id])
  end

  def build_card
    @card ||= card_scope.build
    @card.attributes = card_params
  end

  def card_params
    note_params = params[:card]
    note_params ? note_params.permit(:title, :body) : {}
  end

end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
upjs-rails-0.4.1 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.4.0 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.3.3 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.3.2 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.3.0 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.2.2 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.2.1 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.2.0 spec_app/app/controllers/cards_controller.rb
upjs-rails-0.1.0 spec_app/app/controllers/cards_controller.rb