]> git.openstreetmap.org Git - rails.git/commitdiff
Set defaults properly on redaction model, and remove unnecessary
authorMatt Amos <zerebubuth@gmail.com>
Wed, 4 Apr 2012 15:56:24 +0000 (16:56 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 5 Apr 2012 12:53:32 +0000 (13:53 +0100)
guards around update.

app/controllers/redactions_controller.rb
app/models/redaction.rb

index 03324ad8f30cb0fdcd0b143929c1ef452b8835a8..f8713608d70c148a23b7dd1e37c688caa42a409d 100644 (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')
index ca0ea7232f02755a1e7ecee454c4a49c9ed2a683..43f5b3c7bf70ffb67d8a47d8509c31a9e9fb0a8f 100644 (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