Skip to content

Instantly share code, notes, and snippets.

@alexshagov
Last active April 28, 2016 20:21
Show Gist options
  • Save alexshagov/d93464d39d63757e4d1fdc97d4911e90 to your computer and use it in GitHub Desktop.
Save alexshagov/d93464d39d63757e4d1fdc97d4911e90 to your computer and use it in GitHub Desktop.
blg.1-4
class PicturesController < ApplicationController
def index
@pictures = Picture.order(:priority)
end
def new
@picture = Picture.new
end
def create
@picture = Picture.new(picture_params)
if @picture.save
redirect_to root_path
else
render :new
end
end
def sort
JSON.parse(params[:data]).each do |el|
Picture.find(el["id"]).update_attributes(priority: el["priority"])
end
render nothing: true
end
private
def picture_params
params.require(:picture).permit(:file, :title)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment