fix story edit bug, only check url at new time
This commit is contained in:
parent
a2705a835e
commit
28cd5f8432
|
@ -10,7 +10,9 @@ class StoriesController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@page_title = "Submit a New Story"
|
@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
|
@story.user_id = @user.id
|
||||||
|
|
||||||
if @story.save
|
if @story.save
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Story < ActiveRecord::Base
|
||||||
:allow_blank => true
|
:allow_blank => true
|
||||||
validates_presence_of :user_id
|
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
|
# after this many minutes old, a story cannot be edited
|
||||||
MAX_EDIT_MINS = 30
|
MAX_EDIT_MINS = 30
|
||||||
|
@ -27,7 +27,7 @@ class Story < ActiveRecord::Base
|
||||||
# URI.parse is not very lenient, so we can't use it
|
# URI.parse is not very lenient, so we can't use it
|
||||||
|
|
||||||
if self.url.match(/\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/)
|
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
|
(Time.now - s.created_at) < 30.days
|
||||||
errors.add(:url, "has already been submitted recently")
|
errors.add(:url, "has already been submitted recently")
|
||||||
self.already_posted_story = s
|
self.already_posted_story = s
|
||||||
|
|
Loading…
Reference in a new issue