Make Widget::Card translatable

This commit is contained in:
Javi Martín
2018-09-26 15:55:36 +02:00
parent 2c22ab347d
commit 5bb5cfa7fb
7 changed files with 72 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
class Admin::Widget::CardsController < Admin::BaseController
include Translatable
def new
@card = ::Widget::Card.new(header: header_card?)
@@ -44,6 +45,7 @@ class Admin::Widget::CardsController < Admin::BaseController
params.require(:widget_card).permit(
:label, :title, :description, :link_text, :link_url,
:button_text, :button_url, :alignment, :header,
*translation_params(Widget::Card),
image_attributes: image_attributes
)
end
@@ -52,4 +54,7 @@ class Admin::Widget::CardsController < Admin::BaseController
params[:header_card].present?
end
def resource
Widget::Card.find(params[:id])
end
end

View File

@@ -1,8 +1,15 @@
class Widget::Card < ActiveRecord::Base
include Imageable
# table_name must be set before calls to 'translates'
self.table_name = "widget_cards"
translates :label, touch: true
translates :title, touch: true
translates :description, touch: true
translates :link_text, touch: true
globalize_accessors
def self.header
where(header: true)
end
@@ -10,4 +17,4 @@ class Widget::Card < ActiveRecord::Base
def self.body
where(header: false).order(:created_at)
end
end
end

View File

@@ -1,14 +1,18 @@
<%= form_for [:admin, @card] do |f| %>
<%= render "admin/shared/globalize_locales", resource: @card %>
<%= translatable_form_for [:admin, @card] do |f| %>
<div class="small-12 medium-6">
<%= f.text_field :label %>
<%= f.translatable_text_field :label %>
</div>
<%= f.text_field :title %>
<%= f.translatable_text_field :title %>
<%= f.text_area :description, rows: 5 %>
<%= f.translatable_text_area :description, rows: 5 %>
<div class="small-12 medium-6">
<%= f.text_field :link_text %>
<%= f.translatable_text_field :link_text %>
<%= f.label :link_text %>
</div>
<div class="small-12 medium-6">