Commit 6a84fbaa
Changed files (5)
app
controllers
models
spec
requests
app/controllers/photos_controller.rb
@@ -18,7 +18,6 @@ class PhotosController < ApplicationController
def create
attributes = params[:photo]
attributes[:image] = params[:photo][:image].first if params[:photo][:image].class == Array
- attributes[:is_primary] = !@creation.photos.any?
@photo = @creation.photos.build(attributes)
if @photo.save
app/models/creation.rb
@@ -22,14 +22,14 @@ class Creation < ActiveRecord::Base
def primary_image
if photos.any?
- photos.where(:is_primary => true).first
+ photos.first
else
Photo.new
end
end
def migrate_primary_image
- photo = photos.build({:is_primary => true})
+ photo = photos.build({})
photo.created_at = created_at
photo.updated_at = updated_at
photo.image = image.file
db/migrate/20121108031631_remove_is_primary_from_photos.rb
@@ -0,0 +1,8 @@
+class RemoveIsPrimaryFromPhotos < ActiveRecord::Migration
+ def up
+ remove_column :photos, :is_primary
+ end
+
+ def down
+ end
+end
db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121013031725) do
+ActiveRecord::Schema.define(:version => 20121108031631) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
@@ -128,11 +128,8 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
t.string "image"
t.datetime "created_at"
t.datetime "updated_at"
- t.boolean "is_primary", :default => false
end
- add_index "photos", ["is_primary"], :name => "index_photos_on_is_primary"
-
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.integer "taggable_id"
spec/requests/creations_spec.rb
@@ -4,7 +4,7 @@ describe "Creations" do
describe "GET /creations" do
before(:each) do
creation = FactoryGirl.create(:creation) do |c|
- c.photos.create(:image => File.new(File.join( Rails.root, 'spec/fixtures/images/example.png')), :is_primary => true)
+ c.add_photo(File.new(File.join( Rails.root, 'spec/fixtures/images/example.png')))
c.user = FactoryGirl.create(:user)
end
creation.save!