Skip to content

Commit

Permalink
Add Image Uploading via URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Sep 20, 2013
1 parent 202a37f commit 966e221
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/models/pin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Pin < ActiveRecord::Base
attr_accessible :description, :image
attr_accessible :description, :image, :image_remote_url
has_attached_file :image

validates :description, presence: true
Expand All @@ -10,4 +10,8 @@ class Pin < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>" }

def image_remote_url=(url_value)
self.image = URI.parse(url_value) unless url_value.blank?
super
end
end
3 changes: 2 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">

<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>

<%= link_to "Invite me", root_path, class:"brand" %>
<%= link_to "Invite me", root_path, class: "brand" %>

<div class="nav-collapse">
<ul class="nav">
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<%= render 'layouts/header' %>

<div class="container">
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-#{name}") %>
Expand Down
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 class="form-actions">
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20130920181953_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 that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130919053303) do
ActiveRecord::Schema.define(version: 20130920181953) 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 966e221

Please sign in to comment.