Created
August 1, 2014 00:12
-
-
Save frankie-loves-jesus/c40400731b074cd249b6 to your computer and use it in GitHub Desktop.
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 AddAttachmentColumnsToPhotos < ActiveRecord::Migration | |
| def self.up | |
| change_table :photos do |t| | |
| t.has_attached_file :attachment | |
| end | |
| end | |
| def self.down | |
| drop_attached_file :photos, :attachment | |
| end | |
| 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
| class CreatePhotos < ActiveRecord::Migration | |
| def change | |
| create_table :photos do |t| | |
| t.integer :post_id | |
| t.timestamps | |
| end | |
| end | |
| 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
| <%= f.simple_fields_for :photos do |photo| %> | |
| <%= f.file_field :attachment, :id => "photo_attachment" %> | |
| <% 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
| <div class="photos"> | |
| <% for photo in post.photos %> | |
| <%= image_tag photo.attachment.url(:medium) %> | |
| <% 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 Photo < ActiveRecord::Base | |
| belongs_to :post, :class_name => "Forem::Post" | |
| has_attached_file :attachment, | |
| path: ":rails_root/public/system/attachments/:id/:style/:filename", | |
| url: "/system/attachments/:id/:style/:filename", | |
| styles: { | |
| display: "480x480>", | |
| thumbnail: "70x70#" | |
| }, | |
| convert_options: { all: "-quality 100" }, | |
| processors: [:thumbnail, :compression] | |
| validates_attachment_presence :attachment | |
| validates_attachment :attachment, content_type: { | |
| content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] | |
| } | |
| 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
| Forem::Post.class_eval do | |
| has_many :photos | |
| accepts_nested_attributes_for :photos | |
| 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
| Forem::PostsController.class_eval do | |
| protected | |
| def post_params | |
| params.require(:post).permit(:text, :password, :email, photos_attributes: []) | |
| end | |
| 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
| Forem::TopicsController.class_eval do | |
| def new | |
| authorize! :create_topic, @forum | |
| @topic = @forum.topics.build | |
| post = @topic.posts.build | |
| post.photos.build | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment