@@ -29,7 +29,8 class CustomFieldEnumerationsController < ApplicationController | |||||
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def create |
|
31 | def create | |
32 |
@value = @custom_field.enumerations.build |
|
32 | @value = @custom_field.enumerations.build | |
|
33 | @value.safe_attributes = params[:custom_field_enumeration] | |||
33 | @value.save |
|
34 | @value.save | |
34 | respond_to do |format| |
|
35 | respond_to do |format| | |
35 | format.html { redirect_to custom_field_enumerations_path(@custom_field) } |
|
36 | format.html { redirect_to custom_field_enumerations_path(@custom_field) } | |
@@ -38,7 +39,10 class CustomFieldEnumerationsController < ApplicationController | |||||
38 | end |
|
39 | end | |
39 |
|
40 | |||
40 | def update_each |
|
41 | def update_each | |
41 |
|
|
42 | saved = CustomFieldEnumeration.update_each(@custom_field, params[:custom_field_enumerations]) do |enumeration, enumeration_attributes| | |
|
43 | enumeration.safe_attributes = enumeration_attributes | |||
|
44 | end | |||
|
45 | if saved | |||
42 | flash[:notice] = l(:notice_successful_update) |
|
46 | flash[:notice] = l(:notice_successful_update) | |
43 | end |
|
47 | end | |
44 | redirect_to :action => 'index' |
|
48 | redirect_to :action => 'index' |
@@ -16,6 +16,8 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class CustomFieldEnumeration < ActiveRecord::Base |
|
18 | class CustomFieldEnumeration < ActiveRecord::Base | |
|
19 | include Redmine::SafeAttributes | |||
|
20 | ||||
19 | belongs_to :custom_field |
|
21 | belongs_to :custom_field | |
20 | attr_accessible :name, :active, :position |
|
22 | attr_accessible :name, :active, :position | |
21 |
|
23 | |||
@@ -26,6 +28,10 class CustomFieldEnumeration < ActiveRecord::Base | |||||
26 |
|
28 | |||
27 | scope :active, lambda { where(:active => true) } |
|
29 | scope :active, lambda { where(:active => true) } | |
28 |
|
30 | |||
|
31 | safe_attributes 'name', | |||
|
32 | 'active', | |||
|
33 | 'position' | |||
|
34 | ||||
29 | def to_s |
|
35 | def to_s | |
30 | name.to_s |
|
36 | name.to_s | |
31 | end |
|
37 | end | |
@@ -56,7 +62,11 class CustomFieldEnumeration < ActiveRecord::Base | |||||
56 | attributes.each do |enumeration_id, enumeration_attributes| |
|
62 | attributes.each do |enumeration_id, enumeration_attributes| | |
57 | enumeration = custom_field.enumerations.find_by_id(enumeration_id) |
|
63 | enumeration = custom_field.enumerations.find_by_id(enumeration_id) | |
58 | if enumeration |
|
64 | if enumeration | |
59 | enumeration.attributes = enumeration_attributes |
|
65 | if block_given? | |
|
66 | yield enumeration, enumeration_attributes | |||
|
67 | else | |||
|
68 | enumeration.attributes = enumeration_attributes | |||
|
69 | end | |||
60 | unless enumeration.save |
|
70 | unless enumeration.save | |
61 | raise ActiveRecord::Rollback |
|
71 | raise ActiveRecord::Rollback | |
62 | end |
|
72 | end |
General Comments 0
You need to be logged in to leave comments.
Login now