Class: Admin::PortfoliosController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::PortfoliosController
- Defined in:
- app/controllers/wafflemix/admin/portfolios_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 44 def create @portfolio = Portfolio.new(params[:portfolio]) respond_to do |format| if @portfolio.save format.html { redirect_to @portfolio, notice: 'Portfolio was successfully created.' } format.json { render json: @portfolio, status: :created, location: @portfolio } else format.html { render action: "new" } format.json { render json: @portfolio.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 72 def destroy @portfolio = Portfolio.find(params[:id]) @portfolio.destroy respond_to do |format| format.html { redirect_to portfolios_url } format.json { head :no_content } end end |
#edit ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 36 def edit @portfolio = Portfolio.find(params[:id]) unless @portfolio. @portfolio. end end |
#index ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 8 def index @portfolios = Portfolio.all respond_to do |format| format.html format.json { render json: @portfolios } end end |
#new ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 26 def new @portfolio = Portfolio.new @portfolio. respond_to do |format| format.html format.json { render json: @portfolio } end end |
#show ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 17 def show @portfolio = Portfolio.find(params[:id]) respond_to do |format| format.html format.json { render json: @portfolio } end end |
#sort ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 82 def sort params[:portfolio].sort { |a, b| a <=> b }.each_with_index do |id, index| value = id[1][:id] position = id[1][:position] position = position.to_i + 1 id[1][:parent_id] == "null" ? parent = nil : parent = id[1][:parent_id] Portfolio.update(value, :position => position, :parent_id => parent) end render :nothing => true end |
#update ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/wafflemix/admin/portfolios_controller.rb', line 58 def update @portfolio = Portfolio.find(params[:id]) respond_to do |format| if @portfolio.update_attributes(params[:portfolio]) format.html { redirect_to @portfolio, notice: 'Portfolio was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @portfolio.errors, status: :unprocessable_entity } end end end |