Make Widget::Card translatable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
class AddHomepageContentTranslations < ActiveRecord::Migration
|
||||
|
||||
def self.up
|
||||
Widget::Card.create_translation_table!(
|
||||
label: :string,
|
||||
title: :string,
|
||||
description: :text,
|
||||
link_text: :string
|
||||
)
|
||||
end
|
||||
|
||||
def self.down
|
||||
Widget::Card.drop_translation_table!
|
||||
end
|
||||
end
|
||||
|
||||
14
db/schema.rb
14
db/schema.rb
@@ -1404,6 +1404,20 @@ ActiveRecord::Schema.define(version: 20180813141443) do
|
||||
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
|
||||
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
||||
|
||||
create_table "widget_card_translations", force: :cascade do |t|
|
||||
t.integer "widget_card_id", null: false
|
||||
t.string "locale", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "label"
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.string "link_text"
|
||||
end
|
||||
|
||||
add_index "widget_card_translations", ["locale"], name: "index_widget_card_translations_on_locale", using: :btree
|
||||
add_index "widget_card_translations", ["widget_card_id"], name: "index_widget_card_translations_on_widget_card_id", using: :btree
|
||||
|
||||
create_table "widget_cards", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
|
||||
@@ -7,14 +7,19 @@ feature 'Cards' do
|
||||
login_as(admin)
|
||||
end
|
||||
|
||||
it_behaves_like "translatable",
|
||||
"widget_card",
|
||||
"edit_admin_widget_card_path",
|
||||
%w[title description link_text label]
|
||||
|
||||
scenario "Create", :js do
|
||||
visit admin_homepage_path
|
||||
click_link "Create card"
|
||||
|
||||
fill_in "widget_card_label", with: "Card label"
|
||||
fill_in "widget_card_title", with: "Card text"
|
||||
fill_in "widget_card_description", with: "Card description"
|
||||
fill_in "widget_card_link_text", with: "Link text"
|
||||
fill_in "widget_card_label_en", with: "Card label"
|
||||
fill_in "widget_card_title_en", with: "Card text"
|
||||
fill_in "widget_card_description_en", with: "Card description"
|
||||
fill_in "widget_card_link_text_en", with: "Link text"
|
||||
fill_in "widget_card_link_url", with: "consul.dev"
|
||||
attach_image_to_card
|
||||
click_button "Create card"
|
||||
@@ -59,10 +64,10 @@ feature 'Cards' do
|
||||
click_link "Edit"
|
||||
end
|
||||
|
||||
fill_in "widget_card_label", with: "Card label updated"
|
||||
fill_in "widget_card_title", with: "Card text updated"
|
||||
fill_in "widget_card_description", with: "Card description updated"
|
||||
fill_in "widget_card_link_text", with: "Link text updated"
|
||||
fill_in "widget_card_label_en", with: "Card label updated"
|
||||
fill_in "widget_card_title_en", with: "Card text updated"
|
||||
fill_in "widget_card_description_en", with: "Card description updated"
|
||||
fill_in "widget_card_link_text_en", with: "Link text updated"
|
||||
fill_in "widget_card_link_url", with: "consul.dev updated"
|
||||
click_button "Save card"
|
||||
|
||||
@@ -99,10 +104,10 @@ feature 'Cards' do
|
||||
visit admin_homepage_path
|
||||
click_link "Create header"
|
||||
|
||||
fill_in "widget_card_label", with: "Header label"
|
||||
fill_in "widget_card_title", with: "Header text"
|
||||
fill_in "widget_card_description", with: "Header description"
|
||||
fill_in "widget_card_link_text", with: "Link text"
|
||||
fill_in "widget_card_label_en", with: "Header label"
|
||||
fill_in "widget_card_title_en", with: "Header text"
|
||||
fill_in "widget_card_description_en", with: "Header description"
|
||||
fill_in "widget_card_link_text_en", with: "Link text"
|
||||
fill_in "widget_card_link_url", with: "consul.dev"
|
||||
click_button "Create header"
|
||||
|
||||
@@ -135,4 +140,4 @@ feature 'Cards' do
|
||||
make_visible: true)
|
||||
expect(page).to have_field('widget_card_image_attributes_title', with: "clippy.jpg")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -192,6 +192,8 @@ def update_button_text
|
||||
"Update poll"
|
||||
when "Poll::Question"
|
||||
"Save"
|
||||
when "Widget::Card"
|
||||
"Save card"
|
||||
else
|
||||
"Save changes"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user