From 28cd5f84327b5aafe44ae1dd12de3da1100de78b Mon Sep 17 00:00:00 2001 From: joshua stein Date: Tue, 3 Jul 2012 22:29:14 -0500 Subject: [PATCH] fix story edit bug, only check url at new time --- app/controllers/stories_controller.rb | 4 +++- app/models/story.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index deaf284..c2d040c 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -10,7 +10,9 @@ class StoriesController < ApplicationController def create @page_title = "Submit a New Story" - @story = Story.new(params[:story]) + # we don't allow the url to be changed, so we have to set it manually + @story = Story.new(params[:story].reject{|k,v| k == "url" }) + @story.url = params[:story][:url] @story.user_id = @user.id if @story.save diff --git a/app/models/story.rb b/app/models/story.rb index 18b240a..72406fc 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -10,7 +10,7 @@ class Story < ActiveRecord::Base :allow_blank => true validates_presence_of :user_id - attr_accessible :url, :title, :description, :story_type, :tags_a + attr_accessible :title, :description, :story_type, :tags_a # after this many minutes old, a story cannot be edited MAX_EDIT_MINS = 30 @@ -27,7 +27,7 @@ class Story < ActiveRecord::Base # URI.parse is not very lenient, so we can't use it if self.url.match(/\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/) - if (s = Story.find_by_url(self.url)) && + if self.new_record? && (s = Story.find_by_url(self.url)) && (Time.now - s.created_at) < 30.days errors.add(:url, "has already been submitted recently") self.already_posted_story = s