-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from Floppy/images
Add Images
- Loading branch information
Showing
10 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class ImagesController < ApplicationController | ||
before_action :get_library | ||
before_action :get_model | ||
before_action :get_image | ||
|
||
def show | ||
respond_to do |format| | ||
format.png { send_file File.join(@library.path, @model.path, @image.filename) } | ||
format.jpeg { send_file File.join(@library.path, @model.path, @image.filename) } | ||
end | ||
end | ||
|
||
private | ||
|
||
def get_library | ||
@library = Library.find(params[:library_id]) | ||
end | ||
|
||
def get_model | ||
@model = @library.models.find(params[:model_id]) | ||
end | ||
|
||
def get_image | ||
@image = @model.images.find(params[:id]) | ||
@title = @image.name | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Image < ApplicationRecord | ||
belongs_to :model | ||
validates :filename, presence: true, uniqueness: {scope: :model} | ||
|
||
default_scope { order(:filename) } | ||
|
||
def file_format | ||
File.extname(filename).delete(".").downcase | ||
end | ||
|
||
def name | ||
File.basename(filename, ".*").humanize.titleize | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="col mb-4"> | ||
<div class="card"> | ||
<%= image_tag library_model_image_path(@library, @model, image, format: image.file_format), class: "card-img-top", alt: image.name %> | ||
<div class="card-body"> | ||
<h5 class="card-title"><%= image.name %></h5> | ||
</div> | ||
</div> | ||
</div> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateImages < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :images do |t| | ||
t.references :model, null: false, foreign_key: true | ||
t.string :filename | ||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Image, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |