Skip to content

Commit

Permalink
Only run the file exists validation when it's a new record.
Browse files Browse the repository at this point in the history
  • Loading branch information
quattro004 committed Aug 4, 2013
1 parent d311e75 commit ac74c93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/controllers/pictures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def respond_or_redirect
redirect_to(recipe_path(@picture.imageable_id))
return
end
else
params[:imageable_id] = @picture.imageable_id
params[:imageable_type] = @picture.imageable_type
end
respond_with(@picture)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def picture_contains_data
end

def picture_doesnt_exist
if (Picture.find_by_name(self.name))
if (self.new_record? && Picture.find_by_name(self.name))
errors.add('A picture with this filename', 'already exists')
end
end
Expand Down

0 comments on commit ac74c93

Please sign in to comment.