Commit 5da12ce195320e5c6492d84d8ea815726007f362

Authored by Marcos Pereira
2 parents 12ab2e97 cd5d929a

Merge branch 'article_initialize_bug' into 'master'

Fix article initialize method

The initialize was breaking when the following command was given Folder.find_or_create_by_parent_id_and_name("Downloads"), returning the error: undefined method first for nil class when calling "params.first".

See merge request !834
Showing 1 changed file with 5 additions and 9 deletions   Show diff stats
app/models/article.rb
@@ -28,17 +28,13 @@ class Article < ActiveRecord::Base @@ -28,17 +28,13 @@ class Article < ActiveRecord::Base
28 28
29 def initialize(*params) 29 def initialize(*params)
30 super 30 super
31 -  
32 - if !params.blank?  
33 - if params.first.has_key?(:profile) && !params.first[:profile].blank?  
34 - profile = params.first[:profile]  
35 - self.published = false unless profile.public_profile 31 + if params.present? && params.first.present?
  32 + if params.first.symbolize_keys.has_key?(:published)
  33 + self.published = params.first.symbolize_keys[:published]
  34 + elsif params.first[:profile].present? && !params.first[:profile].public_profile
  35 + self.published = false
36 end 36 end
37 -  
38 - self.published = params.first["published"] if params.first.has_key?("published")  
39 - self.published = params.first[:published] if params.first.has_key?(:published)  
40 end 37 end
41 -  
42 end 38 end
43 39
44 def self.default_search_display 40 def self.default_search_display