Set defaults properly on redaction model, and remove unnecessary

guards around update.
This commit is contained in:
Matt Amos 2012-04-04 16:56:24 +01:00 committed by Tom Hughes
parent a4ded8bb67
commit 0330e10943
2 changed files with 15 additions and 11 deletions

View file

@ -22,9 +22,7 @@ class RedactionsController < ApplicationController
@redaction.user = @user
@redaction.title = params[:redaction][:title]
@redaction.description = params[:redaction][:description]
# didn't see this come in from the form - maybe i'm doing something
# wrong, or markdown is the only thing supported at the moment?
@redaction.description_format = 'markdown'
# note that the description format will default to 'markdown'
if @redaction.save
flash[:notice] = t('redaction.create.flash')
@ -42,14 +40,8 @@ class RedactionsController < ApplicationController
def update
# note - don't update the user ID
if params[:redaction][:title] and params[:redaction][:title] != @redaction.title
@redaction.title = params[:redaction][:title]
end
if params[:redaction][:description] and params[:redaction][:description] != @redaction.description
@redaction.description = params[:redaction][:description]
end
@redaction.title = params[:redaction][:title]
@redaction.description = params[:redaction][:description]
if @redaction.save
flash[:notice] = t('redaction.update.flash')

View file

@ -14,7 +14,19 @@ class Redaction < ActiveRecord::Base
has_many :old_ways
has_many :old_relations
after_initialize :set_defaults
# this method overrides the AR default to provide the rich
# text object for the description field.
def description
RichText.new(read_attribute(:description_format), read_attribute(:description))
end
private
# set the default format to be markdown, in the absence of
# any other setting.
def set_defaults
self.description_format = "markdown" unless self.attribute_present?(:description_format)
end
end