Skip to content

Commit

Permalink
include URL image add
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Sep 16, 2013
1 parent 9806b5a commit a1b0683
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def destroy
format.json { head :no_content }
end
end
end
end
8 changes: 6 additions & 2 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
class Pin < ActiveRecord::Base
attr_accessible :description, :image
attr_accessible :description, :image, :image_remote_url

validates :description, presence: true
validates :user_id, presence: true
has_attached_file :image, styles: { medium: "100x100>" }
validates_attachment :image, presence: true,
validates_attachment :image,
content_type: { content_type: ['image/jpeg' 'image/jpg', 'image/png', 'image/gif'] },
size: { less_than: 5.megabytes }

belongs_to :user
has_attached_file :image, styles: { medium: "320x240>"}

def image_remote_url=(url_value)
self.image = URI.parse(url_value) unless url_value.blank?
super
end
end
1 change: 1 addition & 0 deletions app/views/pins/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<%= f.full_error :image_content_type, class: "alert alert-error" %>

<%= f.input :image, label: "Upload an image" %>
<%= f.input :image_remote_url, label: "or enter a URL" %>
<%= f.input :description, as: :text, input_html: { rows: "3"} %>
</div>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20130916222503_add_image_remote_url_to_pins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImageRemoteUrlToPins < ActiveRecord::Migration
def change
add_column :pins, :image_remote_url, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130916183420) do
ActiveRecord::Schema.define(:version => 20130916222503) do

create_table "pins", :force => true do |t|
t.string "description"
Expand All @@ -22,6 +22,7 @@
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "image_remote_url"
end

add_index "pins", ["user_id"], :name => "index_pins_on_user_id"
Expand Down

0 comments on commit a1b0683

Please sign in to comment.