This file contains hidden or 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 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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 PostForm | |
| include Virtus | |
| include ActiveModel::Model | |
| #Post attributes | |
| attribute :title, String | |
| attribute :body, String | |
| #Tag attributes | |
| attribute :tags, Array[Integer], default: [] |
This file contains hidden or 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 Post < ActiveRecord::Base | |
| has_and_belongs_to_many :tags | |
| end |
This file contains hidden or 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
| 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| |
This file contains hidden or 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
| gem 'virtus' | |
| gem 'simple_form' | |
| group :development, :test do | |
| gem 'pry' | |
| end |
This file contains hidden or 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
| $(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; | |
| } |
This file contains hidden or 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
| <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> |
This file contains hidden or 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 |
This file contains hidden or 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
| Rails.application.routes.draw do | |
| resources :pictures, only: [:index, :create, :new] do | |
| put "sort", on: :collection | |
| end | |
| root 'pictures#index' | |
| end |