Last active
April 28, 2016 20:21
-
-
Save alexshagov/d93464d39d63757e4d1fdc97d4911e90 to your computer and use it in GitHub Desktop.
blg.1-4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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