Я пытаюсь добавить переводы к пользовательскому расширению с именем Post, но когда я пытаюсь сохранить сообщение, я получаю сообщение об ошибке.Как добавить переводы в пользовательское расширение?
Я включил три локали (: es,: en,: pt). Я заметил, что когда я открываю форму, выбранный языковой стандарт по умолчанию не выбран.
Что мне не хватает?
миграции:
class PostTranslations < ActiveRecord::Migration
def up
::Refinery::Posts::Post.create_translation_table!({
:title => :string,
:description => :text },
:migrate_data => true)
remove_column :refinery_posts, :title
remove_column :refinery_posts, :description
end
def self.down
add_column :refinery_posts, :title
add_column :refinery_posts, :description
::Refinery::Posts::Post.drop_translation_table! :migrate_data => true
end
end
_locale_picker.html.erb
<input type="hidden" name="switch_locale" id="switch_locale" value="<%= local_assigns[:current_locale] %>" />
<% if Refinery::I18n.frontend_locales.many? %>
<label><%= t('.language') %></label>
<ul id="switch_locale_picker" class="clearfix">
<% locales = Refinery::I18n.locales.clone %>
<% Refinery::I18n.frontend_locales.each do |locale| %>
<% locale_name = locales.delete(locale) %>
<li<%= %Q{ class=selected} if locale.to_s == local_assigns[:current_locale].to_s %>>
<%= link_to refinery.url_for(:switch_locale => locale, :parent_id => params[:parent_id]), id: locale do %>
<div class="<%=locale %> locale_marker">
<%= locale_text_icon(locale.upcase) %>
</div>
<%= locale_name %>
<% end %>
</li>
<% end %>
</ul>
<% end %>
в сообщение форме:
...
<%= render :partial => "locale_picker",
:locals => {
:current_locale => Thread.current[:globalize_locale]
} if defined?(::Refinery::I18n) %>
...
Схема:
...
create_table "refinery_post_translations", force: :cascade do |t|
t.integer "refinery_post_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title"
t.text "description"
end
add_index "refinery_post_translations", ["locale"], name: "index_refinery_post_translations_on_locale", using: :btree
add_index "refinery_post_translations", ["refinery_post_id"], name: "index_refinery_post_translations_on_refinery_post_id", using: :btree
create_table "refinery_posts", force: :cascade do |t|
t.integer "post_image_id"
t.date "post_date"
t.string "author"
t.integer "position"
t.datetime "created_at"
t.datetime "updated_at"
end
...
Ошибка:
Started POST "/refinery/posts" for ::1 at 2016-06-04 13:22:08 -0400
Processing by Refinery::Posts::Admin::PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"MIHqOv9yCQWkIdS2dKInFbJQtX62+21iqqTDzBtSCOHfBr7TejNIOgQX6iJgI4TWVqa+DVjsemz1DgkhtIZFOw==", "switch_locale"=>"", "post"=>{"post_image_id"=>"", "title"=>"Juan", "post_date(3i)"=>"4", "post_date(2i)"=>"6", "post_date(1i)"=>"2016", "author"=>"", "description"=>""}, "locale"=>:pt}
(0.4ms) SELECT MAX("refinery_posts"."position") FROM "refinery_posts"
Refinery::Authentication::Devise::User Load (0.2ms) SELECT "refinery_authentication_devise_users".* FROM "refinery_authentication_devise_users" WHERE "refinery_authentication_devise_users"."id" = $1 ORDER BY "refinery_authentication_devise_users"."id" ASC LIMIT 1 [["id", 1]]
Refinery::Authentication::Devise::Role Load (0.2ms) SELECT "refinery_authentication_devise_roles".* FROM "refinery_authentication_devise_roles" INNER JOIN "refinery_authentication_devise_roles_users" ON "refinery_authentication_devise_roles"."id" = "refinery_authentication_devise_roles_users"."role_id" WHERE "refinery_authentication_devise_roles_users"."user_id" = $1 [["user_id", 1]]
(0.2ms) BEGIN
(0.3ms) ROLLBACK
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_error_messages.html.erb (0.6ms)
Rendered vendor/extensions/posts/app/views/refinery/posts/admin/posts/_locale_picker.html.erb (2.5ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_image_picker.html.erb (1.1ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_wysiwyg.html.erb (0.4ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_form_actions.html.erb (1.2ms)
Rendered vendor/extensions/posts/app/views/refinery/posts/admin/posts/_form.html.erb (142.5ms)
Rendered vendor/extensions/posts/app/views/refinery/posts/admin/posts/new.html.erb within layouts/refinery/admin (151.0ms)
Rendered refinery/_html_tag.html.erb (1.0ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_javascripts.html.erb (139.9ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_head.html.erb (207.1ms)
Rendered refinery/_site_bar.html.erb (0.7ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_menu_item.html.erb (59.5ms)
Rendered /Users/juan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/refinerycms-9e79b276891f/core/app/views/refinery/admin/_menu.html.erb (89.9ms)
Rendered refinery/_no_script.html.erb (0.3ms)
Rendered refinery/_message.html.erb (0.1ms)