-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
185 additions
and
10 deletions.
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
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
Binary file not shown.
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,15 @@ | ||
class ImagesController < ApplicationController | ||
def create | ||
@post = Post.find(params[:post_id]) | ||
@image = Image.new(params[:image]) | ||
@images.post = @post | ||
|
||
if @image.save | ||
flash[:notice] = "Your #{@images.title} has been posted." | ||
redirect_to @post | ||
else | ||
flash[:error] = "There was a problem posting your media. #{@images.errors.full_messages.join(". ")}." | ||
render 'posts/show' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ def index | |
|
||
def show | ||
@comment = Comment.new | ||
@image = Image.new | ||
end | ||
|
||
def create | ||
|
Binary file not shown.
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 @@ | ||
class Image < ActiveRecord::Base | ||
attr_accessible :path, :post_id, :title, :image | ||
mount_uploader :image, ImageUploader | ||
belongs_to :post | ||
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,55 @@ | ||
# encoding: utf-8 | ||
|
||
class ImageUploader < CarrierWave::Uploader::Base | ||
|
||
# Include RMagick or MiniMagick support: | ||
# include CarrierWave::RMagick | ||
# include CarrierWave::MiniMagick | ||
|
||
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: | ||
# include Sprockets::Helpers::RailsHelper | ||
# include Sprockets::Helpers::IsolatedHelper | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
storage :file | ||
# storage :fog | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
def store_dir | ||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
# process :scale => [200, 300] | ||
# | ||
# def scale(width, height) | ||
# # do something | ||
# end | ||
|
||
# Create different versions of your uploaded files: | ||
# version :thumb do | ||
# process :scale => [50, 50] | ||
# end | ||
|
||
# Add a white list of extensions which are allowed to be uploaded. | ||
# For images you might use something like this: | ||
# def extension_white_list | ||
# %w(jpg jpeg gif png) | ||
# end | ||
|
||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
# def filename | ||
# "something.jpg" if original_filename | ||
# 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
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 @@ | ||
class AddMediaToPost < ActiveRecord::Migration | ||
def change | ||
add_column :posts, :media, :string | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateImages < ActiveRecord::Migration | ||
def change | ||
create_table :images do |t| | ||
t.string :title | ||
t.integer :post_id | ||
t.string :path | ||
|
||
t.timestamps | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddImageIdAddedToPost < ActiveRecord::Migration | ||
def change | ||
add_column :posts, :image_id, :integer | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddImageToPost < ActiveRecord::Migration | ||
def change | ||
add_column :posts, :image, :string | ||
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,32 @@ | ||
@wip | ||
Feature: User creates post and uploads media | ||
As a user | ||
In order to share my thoughts with the world | ||
I want to publish a blog post with media | ||
|
||
Acceptance Criteria: | ||
* Post must have title and body | ||
* Post must be publicly visible once saved | ||
* Post must show media in the post | ||
|
||
|
||
Background: | ||
Given I am signed in | ||
|
||
Scenario: Happy Path | ||
Given I am on the homepage | ||
And I click "Write Post" | ||
Then I should see "Fill in your blog post here" | ||
When I fill in "My thoughts are grand" for "Title" | ||
And I fill in "Actually, they aren't" for "Body" | ||
And I press "Publish" | ||
Then I should see "Your post has been published" | ||
And I should see the title "My thoughts are grand" | ||
And I should see "Actually, they aren't" | ||
And show me the page | ||
And I attach "/Users/sam/Desktop/myfile.mov" to "media_media" | ||
And I fill in "My video" for "Title" | ||
Then I should see "Your post has been published" | ||
And I should see the title "My thoughts are grand" | ||
And I should see "Actually, they aren't" | ||
And I should see my video |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+28.6 KB
public/uploads/media/media/5/Screen_Shot_2012-09-23_at_10.37.14_AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added
BIN
+28.6 KB
public/uploads/media/media/7/Screen_Shot_2012-09-23_at_10.37.14_AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 'spec_helper' | ||
|
||
describe Image do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
1 comment
on commit 13ac356
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't be committing those temporary uploaded files. You need to remove the items in public/uploads and add public/uploads
to the .gitignore
.
I don't think you need both image_id and image added to the post. Which one is actually necessary?