From 0e19aa4362a0524d900044fc9dc69e177337eca0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 10 Dec 2010 10:12:19 +0000 Subject: Fixed: error when serializing back objects with custom fields using ActiveResource (#6403). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4480 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/custom_fields_helper.rb | 11 +++++++++++ app/views/issues/index.api.rsb | 6 +----- app/views/issues/show.api.rsb | 6 +----- app/views/projects/index.api.rsb | 8 +++----- app/views/projects/show.api.rsb | 6 +----- app/views/users/index.api.rsb | 6 +----- app/views/users/show.api.rsb | 6 +----- 7 files changed, 19 insertions(+), 30 deletions(-) (limited to 'app') diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 189467409..107d0ac87 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -104,4 +104,15 @@ module CustomFieldsHelper def custom_field_formats_for_select Redmine::CustomFieldFormat.as_select end + + # Renders the custom_values in api views + def render_api_custom_values(custom_values, api) + api.array :custom_fields do + custom_values.each do |custom_value| + api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do + api.value custom_value.value + end + end + end unless custom_values.empty? + end end diff --git a/app/views/issues/index.api.rsb b/app/views/issues/index.api.rsb index a63b07a09..f30ee55bb 100644 --- a/app/views/issues/index.api.rsb +++ b/app/views/issues/index.api.rsb @@ -19,11 +19,7 @@ api.array :issues do api.done_ratio issue.done_ratio api.estimated_hours issue.estimated_hours - api.array :custom_fields do - issue.custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end + render_api_custom_values issue.custom_field_values, api api.created_on issue.created_on api.updated_on issue.updated_on diff --git a/app/views/issues/show.api.rsb b/app/views/issues/show.api.rsb index 001cabe11..02e7fdd29 100644 --- a/app/views/issues/show.api.rsb +++ b/app/views/issues/show.api.rsb @@ -20,11 +20,7 @@ api.issue do api.spent_hours @issue.spent_hours end - api.array :custom_fields do - @issue.custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end unless @issue.custom_field_values.empty? + render_api_custom_values @issue.custom_field_values, api api.created_on @issue.created_on api.updated_on @issue.updated_on diff --git a/app/views/projects/index.api.rsb b/app/views/projects/index.api.rsb index e65477a23..4ffee934f 100644 --- a/app/views/projects/index.api.rsb +++ b/app/views/projects/index.api.rsb @@ -6,11 +6,9 @@ api.array :projects do api.identifier project.identifier api.description project.description api.parent(:id => project.parent_id, :name => project.parent.name) unless project.parent.nil? - api.array :custom_fields do - project.visible_custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end unless project.custom_field_values.empty? + + render_api_custom_values project.visible_custom_field_values, api + api.created_on project.created_on api.updated_on project.updated_on end diff --git a/app/views/projects/show.api.rsb b/app/views/projects/show.api.rsb index 4479e500f..dc0263712 100644 --- a/app/views/projects/show.api.rsb +++ b/app/views/projects/show.api.rsb @@ -5,11 +5,7 @@ api.project do api.description @project.description api.homepage @project.homepage - api.array :custom_fields do - @project.visible_custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end unless @project.custom_field_values.empty? + render_api_custom_values @project.visible_custom_field_values, api api.created_on @project.created_on api.updated_on @project.updated_on diff --git a/app/views/users/index.api.rsb b/app/views/users/index.api.rsb index 815abef2b..722b44ac1 100644 --- a/app/views/users/index.api.rsb +++ b/app/views/users/index.api.rsb @@ -9,11 +9,7 @@ api.array :users do api.created_on user.created_on api.last_login_on user.last_login_on - api.array :custom_fields do - user.visible_custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end unless user.visible_custom_field_values.empty? + render_api_custom_values user.visible_custom_field_values, api end end end diff --git a/app/views/users/show.api.rsb b/app/views/users/show.api.rsb index 6c3dd9018..c177d49e9 100644 --- a/app/views/users/show.api.rsb +++ b/app/views/users/show.api.rsb @@ -7,11 +7,7 @@ api.user do api.created_on @user.created_on api.last_login_on @user.last_login_on - api.array :custom_fields do - @user.visible_custom_field_values.each do |custom_value| - api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name - end - end unless @user.visible_custom_field_values.empty? + render_api_custom_values @user.visible_custom_field_values, api api.array :memberships do @memberships.each do |membership| -- cgit v1.2.3