Commit 8e1425f12945a33a9de86b975c5d5c82989ad5bd

Authored by Leandro Santos
1 parent 86274a0d

refactoring article creation

Showing 1 changed file with 6 additions and 2 deletions   Show diff stats
lib/api/v1/articles.rb
... ... @@ -65,8 +65,12 @@ module API
65 65 # POST api/v1/communites/:community_id/articles?private_toke=234298743290432&article[name]=title&article[body]=body
66 66 post do
67 67 community = environment.communities.find(params[:community_id])
68   - article = community.articles.build(params[:article].merge(:last_changed_by => current_person))
69   - article.type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
  68 + klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]
  69 + article = klass_type.constantize.new(params[:article])
  70 + article.last_changed_by = current_person
  71 + article.created_by= current_person
  72 + article.profile = community
  73 +
70 74 if !article.save
71 75 render_api_errors!(article.errors.full_messages)
72 76 end
... ...