fix story edit bug, only check url at new time

This commit is contained in:
joshua stein 2012-07-03 22:29:14 -05:00
parent a2705a835e
commit 28cd5f8432
2 changed files with 5 additions and 3 deletions

View file

@ -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

View file

@ -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