Created
March 23, 2015 11:29
-
-
Save universal/02429a99a27d4780d505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Schemas | |
| An update_call of the item_classification | |
| Processing ItemClassificationsController#update (for 127.0.0.1 at 2015-03-23 11:15:54) [PUT] | |
| Parameters: {"_method"=>"put", "commit"=>"Update", "action"=>"update", "controller"=>"item_classifications", "id"=>"4", "item_classification"=>{"title_translation"=>{"value"=>"This is a title", "locale_id"=>"2"}}} | |
| Example of the problem: | |
| >> item_classification = ItemClassification.find(4) | |
| => #<ItemClassification id: 4, previous_level_id: 0, level: 1, name: "Objects", permalink: "objects", position: 5, items_count: 4802, description: "a description", enabled: true,..."> | |
| >> item_classification.build_title_translation(:value => 'This is a title', :locale_id => 2) | |
| #<TitleTranslation id: nil, locale_id: 2, key: "metatags.titles.item_classification_4.title", value: "This is a title", updated_at: nil> | |
| >> item_classification.save | |
| => true | |
| >> item_classification.title_translation | |
| => #<TitleTranslation id: 10329, locale_id: 2, key: 4, value: "Prodotti per bambini", updated_at: "2015-03-23 10:25:23"> | |
| What am I doing wrong? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ItemClassification < ActiveRecord::Base | |
| has_one :title_translation, :foreign_key => 'key', :primary_key => :custom_title_key, :conditions => ['locale_id = 2'] | |
| accepts_nested_attributes_for :title_translation | |
| private | |
| def custom_title_key | |
| "metatags.titles.item_classification_#{id}.title" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create_table "TitleTranslation", :force => true do |t| | |
| t.integer "locale_id" | |
| t.string "key" | |
| t.text "value" | |
| t.datetime "updated_at" | |
| end | |
| create_table "item_classifications", :force => true do |t| | |
| t.integer "previous_level_id" | |
| t.integer "level" | |
| t.string "name" | |
| t.string "permalink" | |
| t.integer "position" | |
| t.integer "items_count", :default => 0 | |
| t.text "description" | |
| t.boolean "enabled" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TitleTranslation < ActiveRecord::Base | |
| belongs_to :item_classification, :foreign_key => 'key', :primary_key => :custom_title_key | |
| attr_accessible :item_classification | |
| def custom_title_key | |
| "metatags.titles.item_classification_#{item_classification.id}.title" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment