Commit 8e1425f12945a33a9de86b975c5d5c82989ad5bd
1 parent
86274a0d
Exists in
staging
and in
4 other branches
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,8 +65,12 @@ module API | ||
| 65 | # POST api/v1/communites/:community_id/articles?private_toke=234298743290432&article[name]=title&article[body]=body | 65 | # POST api/v1/communites/:community_id/articles?private_toke=234298743290432&article[name]=title&article[body]=body |
| 66 | post do | 66 | post do |
| 67 | community = environment.communities.find(params[:community_id]) | 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 | if !article.save | 74 | if !article.save |
| 71 | render_api_errors!(article.errors.full_messages) | 75 | render_api_errors!(article.errors.full_messages) |
| 72 | end | 76 | end |