Sha256: ec59763f78861c17fe42600e9f7de82bbed3f5ef75d2e06361e9a08c298e0cb1

Contents?: true

Size: 1.72 KB

Versions: 18

Compression:

Stored size: 1.72 KB

Contents

module MechanizeStore
  class FlagsController < ApplicationController
    before_action :set_flag, only: [:show, :edit, :update, :destroy]

    respond_to :html, :json, :xml

    def index
      @search = Flag.search(params[:q])

      @flags = @search.result.paginate(page: params[:page])

      respond_with @flags
    end

    def show
      respond_with @flag
    end

    def new
      @flag = Flag.new
      respond_with @flag
    end

    def edit
      respond_with @flag
    end

    def create
      @flag = Flag.new(flag_params)

      respond_with @flag do |format|
        if @flag.save 
          format.html do 
            flash[:notice] = I18n.t(:created, model: I18n.t(:flag, scope: "activerecord.models")) 
            redirect_to @flag
          end
        else
          format.html { render action: "new" }
        end
      end
    end

    def update
      @flag = Flag.find(params[:id])

      respond_with @flag do |format|
        if @flag.update(flag_params)
          format.html do 
            flash[:notice] = I18n.t(:updated, model: I18n.t(:flag, scope: "activerecord.models")) 
            redirect_to @flag
          end
        else
          format.html { render action: "edit" }
        end
      end
    end

    def destroy
      @flag = Flag.find(params[:id])
      
      flash[:alert] = I18n.t(:deleted, model: I18n.t(:flag, scope: "activerecord.models")) if @flag.destroy

      respond_with @flag, :location => flags_url
    end

    private
    # Use callbacks to share common setup or constraints between actions.
    def set_flag
      @flag = Flag.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def flag_params
      params.require(:flag).permit(:name)
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mechanize_store-0.0.19 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.18 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.17 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.16 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.15 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.14 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.13 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.12 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.11 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.10 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.8 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.7 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.6 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.5 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.4 app/controllers/mechanize_store/flags_controller.rb
mechanize_store-0.0.3 app/controllers/mechanize_store/flags_controller.rb
mechanize-store-0.0.2 app/controllers/mechanize_store/flags_controller.rb
mechanize-store-0.0.1 app/controllers/mechanize_store/flags_controller.rb