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