Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using paperclip to attach images #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

# ignore al .DS_store files of MAC OSX
.DS_Store

public/system
.project
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ group :assets do
end

gem 'jquery-rails'
gem 'paperclip'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
19 changes: 13 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GEM
ansi (1.4.1)
arel (2.2.1)
builder (3.0.0)
cocaine (0.2.0)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
railties (~> 3.1.0)
Expand All @@ -40,20 +41,25 @@ GEM
execjs
coffee-script-source (1.1.3)
erubis (2.7.0)
execjs (1.2.9)
execjs (1.2.11)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.18)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
json (1.6.3)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.0.3)
multi_json (1.0.4)
paperclip (2.4.5)
activerecord (>= 2.3.0)
activesupport (>= 2.3.2)
cocaine (>= 0.0.2)
mime-types
polyglot (0.3.3)
rack (1.3.5)
rack-cache (1.1)
Expand Down Expand Up @@ -82,7 +88,7 @@ GEM
rake (0.9.2.2)
rdoc (3.11)
json (~> 1.4)
sass (3.1.10)
sass (3.1.11)
sass-rails (3.1.5)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
Expand All @@ -92,7 +98,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -111,6 +117,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.1.1)
jquery-rails
paperclip
rails (= 3.1.3)
sass-rails (~> 3.1.5)
sqlite3
Expand Down
1 change: 1 addition & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Site < ActiveRecord::Base
belongs_to :type
has_attached_file :image
end
4 changes: 2 additions & 2 deletions app/views/sites/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<%= f.text_field :zoom %>
</div>
<div class="field">
<%= f.label :image_url %><br />
<%= f.text_field :image_url %>
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="actions">
<%= f.submit %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/sites/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h1><%= @site.type.name if @site.type %></h1>

<%= image_tag(@site.image_url, :class => 'site_image') %>
<%= image_tag(@site.image.url, :class => 'site_image') %>

<h3><%= @site.name %></h3>

Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20111207113324_add_image_columns_to_site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddImageColumnsToSite < ActiveRecord::Migration
def self.up
add_column :sites, :image_file_name, :string
add_column :sites, :image_content_type, :string
add_column :sites, :image_file_size, :integer
add_column :sites, :image_updated_at, :datetime
end

def self.down
remove_column :sites, :image_file_name
remove_column :sites, :image_content_type
remove_column :sites, :image_file_size
remove_column :sites, :image_updated_at
end
end
12 changes: 8 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111127165324) do
ActiveRecord::Schema.define(:version => 20111207113324) do

create_table "sites", :force => true do |t|
t.string "name"
t.text "description"
t.integer "type_id"
t.decimal "latitude", :precision => 8, :scale => 6
t.decimal "longitude", :precision => 8, :scale => 6
t.decimal "zoom", :precision => 8, :scale => 6
t.decimal "latitude", :precision => 8, :scale => 6
t.decimal "longitude", :precision => 8, :scale => 6
t.decimal "zoom", :precision => 8, :scale => 6
t.string "image_url"
t.datetime "created_at"
t.datetime "updated_at"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end

create_table "types", :force => true do |t|
Expand Down
241 changes: 0 additions & 241 deletions public/index.html

This file was deleted.