Skip to content

Instantly share code, notes, and snippets.

@1syo
Last active November 19, 2015 02:17
Show Gist options
  • Save 1syo/6ed3be4f7f92beb82815 to your computer and use it in GitHub Desktop.
Save 1syo/6ed3be4f7f92beb82815 to your computer and use it in GitHub Desktop.
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title, null: false
t.text :content, null: false
t.binary :image
t.timestamps null: false
end
end
end
class Article < ActiveRecord::Base
end
class ArticlesController < ApplicationController
def show
@article = Article.find(params[:id])
end
end
class ImagesController < ApplicationController
def show
article = Article.find(params[:id])
send_data article.image, type: 'image/png', disposition: 'inline'
end
end
Rails.application.routes.draw do
resources :images, only: :show
resources :articles, only: :show
end
<h1><%= @article.title %></h1>
<p>
<%= @article.content %>
<%= image_tag '/images/1' %>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment