Sha256: 969373e5b9d27f08f96f26ae2043ab7b7ec700204d46fa8d45771ff0ed40e286

Contents?: true

Size: 1.76 KB

Versions: 9

Compression:

Stored size: 1.76 KB

Contents

module Georgia
  class WidgetsController < ApplicationController

    load_and_authorize_resource class: Georgia::Widget

    def index
      @widgets = Widget.order(:created_at).page(params[:page]).in_groups_of(4, false)
      @widget = Widget.new
      @widget.contents.build(locale: current_locale)
    end

    def edit
      @widget = Widget.find(params[:id])
    end

    def create
      @widget = Widget.new(params[:widget])

      if @widget.save
        respond_to do |format|
          format.html { redirect_to widgets_url, notice: "Widget was successfully updated." }
          format.js { render layout: false }
        end
      else
        respond_to do |format|
          format.html { redirect_to widgets_url, alert: "Oups. Something went wrong." }
          format.js { render layout: false }
        end
      end

    end

    def update
      @widget = Widget.find(params[:id])
      if @widget.update_attributes(params[:widget])
        respond_to do |format|
          format.html { redirect_to widgets_url, notice: "Widget was successfully updated." }
          format.js { head :ok }
        end
      else
        respond_to do |format|
          format.html { render :index, alert: "Oups. Something went wrong." }
          format.js { head :internal_server_error }
        end
      end
    end

    def destroy
      @widget = Widget.find(params[:id])
      if @widget.destroy
        respond_to do |format|
          format.html { redirect_to widgets_url, notice: "Widget was successfully deleted." }
          format.js { head :ok }
        end
      else
        respond_to do |format|
          format.html { redirect_to widgets_url, alert: "Oups. Something went wrong." }
          format.js { head :internal_server_error }
        end
      end


    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
georgia-0.7.8 app/controllers/georgia/widgets_controller.rb
georgia-0.7.7 app/controllers/georgia/widgets_controller.rb
georgia-0.7.6 app/controllers/georgia/widgets_controller.rb
georgia-0.7.5 app/controllers/georgia/widgets_controller.rb
georgia-0.7.4 app/controllers/georgia/widgets_controller.rb
georgia-0.7.3 app/controllers/georgia/widgets_controller.rb
georgia-0.7.2 app/controllers/georgia/widgets_controller.rb
georgia-0.7.1 app/controllers/georgia/widgets_controller.rb
georgia-0.7.0 app/controllers/georgia/widgets_controller.rb