Skip to content

Instantly share code, notes, and snippets.

View alexshagov's full-sized avatar
💭
I may be slow to respond.

Alexander Shagov alexshagov

💭
I may be slow to respond.
View GitHub Profile
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
# GET /posts
# GET /posts.json
def index
@posts = Post.all
end
# GET /posts/1
@alexshagov
alexshagov / post_form.rb
Last active May 9, 2016 16:16
blog 2-4
class PostForm
include Virtus
include ActiveModel::Model
#Post attributes
attribute :post, Object
attribute :title, String
attribute :body, String
#Tag attributes
attribute :tags, String # first tag,second tag,third tag
class PostForm
include Virtus
include ActiveModel::Model
#Post attributes
attribute :title, String
attribute :body, String
#Tag attributes
attribute :tags, Array[Integer], default: []
@alexshagov
alexshagov / post.rb
Last active May 10, 2016 17:11
blog 2-3
class Post < ActiveRecord::Base
has_and_belongs_to_many :tags
end
ActiveRecord::Schema.define(version: 20160509115901) do
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "posts_tags", force: :cascade do |t|
gem 'virtus'
gem 'simple_form'
group :development, :test do
gem 'pry'
end
$(function(){
var updated_order = function(){
var data_arr = [];
$.each($(".picture"), function(index){
$(this).attr("priority", index);
data_arr.push({id: $(this).attr("data-id"), priority: index })
});
return data_arr;
}
<div class="container">
<h3><%= link_to "Add picture", new_picture_path %></h3>
<% @pictures.each do |picture| %>
<div class = "picture" data-id = "<%= picture.id %>">
<%= image_tag(picture.file.url(:medium)) %>
</div>
<% end %>
</div>
class PicturesController < ApplicationController
def index
@pictures = Picture.order(:priority)
end
def new
@picture = Picture.new
end
def create
Rails.application.routes.draw do
resources :pictures, only: [:index, :create, :new] do
put "sort", on: :collection
end
root 'pictures#index'
end