{"id":317458,"date":"2021-02-04T09:01:32","date_gmt":"2021-02-04T09:01:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=317458"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=317458","title":{"rendered":"\u041a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 Active Admin"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24e\/9b8\/ed3\/24e9b8ed35ab19a2838163d0342fadf7.jpg\" width=\"768\" height=\"450\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/514506\">\u041d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0430\u0439\u0434 \u043f\u043e Active Admin<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 <strong>Active Admin<\/strong>, \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0444\u043e\u0440\u043c\u0430 \u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0448\u044c \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u043d\u0435 \u043f\u043e\u0440\u0430 \u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0443, \u0430 \u043d\u0435 \u043d\u0430\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0440\u043e\u0434\u043d\u043e\u0439, \u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 jQuery-\u043a\u043e\u0434.<\/p>\n<p>\u041c\u044b \u0432 \u0414\u043e\u043c\u041a\u043b\u0438\u043a \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<strong> Vue.js<\/strong> \u0438 <strong>React<\/strong>, \u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 Active Admin.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 Active Admin \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>Webpacker<\/strong> \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u041e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432&nbsp;<a href=\"https:\/\/activeadmin.info\/0-installation.html#webpacker\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<h3>Active Admin \u0441 Webpacker<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0433\u0435\u043c <strong>react-rails<\/strong> (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/github.com\/reactjs\/react-rails#get-started-with-webpacker\">README<\/a>):<\/p>\n<pre><code class=\"ruby\"># Gemfile gem 'react-rails', '~&gt; 2.6'<\/code><\/pre>\n<pre><code class=\"bash\">bundle install rails webpacker:install:react rails generate react:install<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 hello world  \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e&nbsp;<code>app\/javascript\/components<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/components\/Hello.jsx import * as React from 'react';  const Hello = ({name}) =&gt; {   return(     &lt;div&gt;Hello {name}!&lt;\/div&gt;   ); };  export default Hello;<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u0432\u0438\u0434\u043d\u044b \u0432 Active Admin, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432&nbsp;<code>app\/javascript\/packs\/activeadmin.js<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/packs\/activeadmin.js \/\/ ...  \/\/ Support component names relative to this directory: var componentRequireContext = require.context(\"components\", true); var ReactRailsUJS = require(\"react_ujs\"); ReactRailsUJS.useContext(componentRequireContext);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c React-\u0432\u0438\u0434\u0436\u0435\u0442\u044b (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/514506\">\u041d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0430\u0439\u0434 \u043f\u043e Active Admin<\/a>):<\/p>\n<pre><code class=\"ruby\"># app\/admin\/components\/react_component.rb module Admin   module Components     # Defines a `react_component` arbre component. It allows     # to include react components into Active Admin using react-rails.     #     # @example     #     # show do     #   panel do     #     react_component 'Post', { title: 'My post' }     #   end     # end     #     class React &lt; ActiveAdmin::Component       class ReactComponentBuilder         include ::React::Rails::ViewHelper         include ActionView::Helpers::TagHelper       end        builder_method :react_component        def to_s         ReactComponentBuilder.new.react_component(*@args, &amp;@block)       end        def build(*args, &amp;block)         @args = args         @block = block       end     end   end end<\/code><\/pre>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 <code>dashboard.rb<\/code>:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }   end end<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1fa\/713\/9df\/1fa7139df520dbb6389657d45bb3cddc.jpg\" width=\"1444\" height=\"696\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u044b! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 Active Admin!<\/p>\n<h2>\u0411\u043e\u043d\u0443\u0441: \u0443\u0431\u0438\u0440\u0430\u0435\u043c Sprockets \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0415\u0441\u043b\u0438 Assets Pipeline \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e Active Admin \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.9, \u0438 \u0437\u0430\u0442\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>require 'sprockets\/railtie'<\/code>  \u0438\u0437 <code>config\/application.rb<\/code> (\u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c <code>require 'rails\/all'<\/code>, \u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u0432\u043e \u0447\u0442\u043e <a href=\"https:\/\/guides.rubyonrails.org\/initialization.html#loading-rails\">\u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/a> \u044d\u0442\u043e\u0442 <code>require<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 <code>config.assets.compile = false<\/code> \u0438\u0437 <code>config\/environments\/production.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 <code>config.assets.debug = true<\/code> \u0438 <code>config.assets.quiet = true<\/code>  \u0438\u0437 <code>config\/environments\/development.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>gem 'sass-rails'<\/code> \u0438\u0437 <code>Gemfile<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>initializers\/assets.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>app\/assets<\/code> \u0441\u043e \u0432\u0441\u0435\u043c \u0435\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<h2>Active Admin \u0441 Assets Pipeline<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 Active Admin \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>Sprockets<\/strong>, \u0442\u043e react-rails \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Assets Pipeline (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/github.com\/reactjs\/react-rails#use-with-asset-pipeline\">README<\/a>). \u042f \u0441\u043c\u043e\u0433 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <code>hello.jsx<\/code> \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u043d\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0431\u044b \u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e webpacker \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>gem \"webpacker\"<\/code>\u0432 <code>Gemfile<\/code>,  \u0437\u0430\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 react-rails, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0444\u0430\u0439\u043b\u0430 <code>app\/javascript\/packs\/activeadmin.js<\/code>; \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/packs\/activeadmin.js  \/\/ Support component names relative to this directory: var componentRequireContext = require.context(\"components\", true); var ReactRailsUJS = require(\"react_ujs\"); ReactRailsUJS.useContext(componentRequireContext);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435: \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 sprockets, Active Admin \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 pack, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     script src: asset_pack_path(\"activeadmin.js\")     react_component 'Hello', { name: 'David' }   end end<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u00ab\u0447\u0438\u0441\u0442\u044b\u0435\u00bb \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Active Admin:<\/p>\n<pre><code class=\"ruby\"># lib\/active_admin\/extra_headers.rb  module ActiveAdmin   module ExtraHeaders     def build_active_admin_head(*args)       super       return unless controller.respond_to?(:extra_headers)        within head do         controller.extra_headers.each do |extra_header|           text_node(extra_header)         end       end     end   end end<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"ruby\"># config\/initializers\/active_admin.rb  require_relative '..\/..\/lib\/active_admin\/extra_headers'  ActiveAdmin::Views::Pages::Base.send(:prepend, ActiveAdmin::ExtraHeaders)<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>app\/admin\/dashboard.rb<\/code>:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }   end    controller do     def extra_headers       [helpers.javascript_pack_tag('activeadmin')]     end   end end<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0445\u0430\u043a. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u043d\u043e \u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0435.<\/p>\n<h2>React-rails \u0438 Webpacker \u0432 \u0431\u043e\u044e<\/h2>\n<p>\u041f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043a \u0431\u043e\u0435\u0432\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c: \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 Typescript \u0438 \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 react-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e .tsx-\u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 Typescript:<\/p>\n<pre><code class=\"bash\">rails webpacker:install:typescript yarn add -D @types\/react @types\/react-dom<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0437 <code>.jsx<\/code> \u0432 <code>.tsx<\/code>:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react';  const Hello = ({name}: {name: string}) =&gt; {   return(     &lt;div&gt;Hello {name}!&lt;\/div&gt;   ); };  export default Hello;<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c <a href=\"https:\/\/github.com\/uber\/react-vis\">react-vis<\/a>. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">yarn add -D react-vis @types\/react-vis<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>app\/components\/javascript\/Plot.tsx<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/components\/javascript\/Plot.tsx  import * as React from 'react'; import 'react-vis\/dist\/style.css'; import { XYPlot, LineSeries, LineSeriesPoint } from 'react-vis';  type Params = {   data: LineSeriesPoint[]; } const Plot = ({data}: Params) =&gt; {   return (     &lt;div className=\"Plot\"&gt;       &lt;XYPlot height={300} width={300}&gt;         &lt;LineSeries data={data} \/&gt;       &lt;\/XYPlot&gt;     &lt;\/div&gt;   ); };  export default Plot;<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb  ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }     data = [       { x: 0, y: 5 },       { x: 2, y: 7 },       { x: 5, y: 8 },       { x: 7, y: 7 },       { x: 8, y: 3 },       { x: 6, y: 0 },       { x: 0, y: -5 },       { x: -6, y: 0 },       { x: -8, y: 3 },       { x: -7, y: 7 },       { x: -5, y: 8 },       { x: -2, y: 7 },       { x: 0, y: 5 }     ]     react_component 'Plot', { data: data }   end end <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32e\/4fa\/a58\/32e4faa58aefbf9d2930c4bd9e585a51.jpg\" width=\"1856\" height=\"1044\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0451, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c React \u0432 Active Admin, \u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0441\u0432\u0435\u0442\u043b\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0432\u0437\u043e\u0440\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u043c \u0440\u0435\u0448\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c) \u044d\u0442\u043e \u0437\u043d\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/535866\/\"> https:\/\/habr.com\/ru\/company\/domclick\/blog\/535866\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/514506\">\u041d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0430\u0439\u0434 \u043f\u043e Active Admin<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 <strong>Active Admin<\/strong>, \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0444\u043e\u0440\u043c\u0430 \u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438 \u0438\u043b\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0448\u044c \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f, \u043d\u0435 \u043f\u043e\u0440\u0430 \u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0443, \u0430 \u043d\u0435 \u043d\u0430\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0440\u043e\u0434\u043d\u043e\u0439, \u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 jQuery-\u043a\u043e\u0434.<\/p>\n<p>\u041c\u044b \u0432 \u0414\u043e\u043c\u041a\u043b\u0438\u043a \u0432 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<strong> Vue.js<\/strong> \u0438 <strong>React<\/strong>, \u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 Active Admin.<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 Active Admin \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <strong>Webpacker<\/strong> \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438. \u041e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0436\u0438\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432&nbsp;<a href=\"https:\/\/activeadmin.info\/0-installation.html#webpacker\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<h3>Active Admin \u0441 Webpacker<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0433\u0435\u043c <strong>react-rails<\/strong> (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/github.com\/reactjs\/react-rails#get-started-with-webpacker\">README<\/a>):<\/p>\n<pre><code class=\"ruby\"># Gemfile gem 'react-rails', '~&gt; 2.6'<\/code><\/pre>\n<pre><code class=\"bash\">bundle install rails webpacker:install:react rails generate react:install<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 hello world  \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e&nbsp;<code>app\/javascript\/components<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/components\/Hello.jsx import * as React from 'react';  const Hello = ({name}) =&gt; {   return(     &lt;div&gt;Hello {name}!&lt;\/div&gt;   ); };  export default Hello;<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u0438 \u0432\u0438\u0434\u043d\u044b \u0432 Active Admin, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432&nbsp;<code>app\/javascript\/packs\/activeadmin.js<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/packs\/activeadmin.js \/\/ ...  \/\/ Support component names relative to this directory: var componentRequireContext = require.context(\"components\", true); var ReactRailsUJS = require(\"react_ujs\"); ReactRailsUJS.useContext(componentRequireContext);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c React-\u0432\u0438\u0434\u0436\u0435\u0442\u044b (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/514506\">\u041d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0433\u0430\u0439\u0434 \u043f\u043e Active Admin<\/a>):<\/p>\n<pre><code class=\"ruby\"># app\/admin\/components\/react_component.rb module Admin   module Components     # Defines a `react_component` arbre component. It allows     # to include react components into Active Admin using react-rails.     #     # @example     #     # show do     #   panel do     #     react_component 'Post', { title: 'My post' }     #   end     # end     #     class React &lt; ActiveAdmin::Component       class ReactComponentBuilder         include ::React::Rails::ViewHelper         include ActionView::Helpers::TagHelper       end        builder_method :react_component        def to_s         ReactComponentBuilder.new.react_component(*@args, &amp;@block)       end        def build(*args, &amp;block)         @args = args         @block = block       end     end   end end<\/code><\/pre>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 <code>dashboard.rb<\/code>:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }   end end<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u044b! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 Active Admin!<\/p>\n<h2>\u0411\u043e\u043d\u0443\u0441: \u0443\u0431\u0438\u0440\u0430\u0435\u043c Sprockets \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0415\u0441\u043b\u0438 Assets Pipeline \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043e\u0442 \u043d\u0435\u0433\u043e \u043d\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f? \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e Active Admin \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.9, \u0438 \u0437\u0430\u0442\u0435\u043c:<\/p>\n<ul>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>require 'sprockets\/railtie'<\/code>  \u0438\u0437 <code>config\/application.rb<\/code> (\u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c <code>require 'rails\/all'<\/code>, \u0442\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u0432\u043e \u0447\u0442\u043e <a href=\"https:\/\/guides.rubyonrails.org\/initialization.html#loading-rails\">\u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/a> \u044d\u0442\u043e\u0442 <code>require<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0443 <code>config.assets.compile = false<\/code> \u0438\u0437 <code>config\/environments\/production.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 <code>config.assets.debug = true<\/code> \u0438 <code>config.assets.quiet = true<\/code>  \u0438\u0437 <code>config\/environments\/development.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>gem 'sass-rails'<\/code> \u0438\u0437 <code>Gemfile<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0443\u0434\u0430\u043b\u0438\u0442\u0435 <code>initializers\/assets.rb<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>app\/assets<\/code> \u0441\u043e \u0432\u0441\u0435\u043c \u0435\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<h2>Active Admin \u0441 Assets Pipeline<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 Active Admin \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>Sprockets<\/strong>, \u0442\u043e react-rails \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Assets Pipeline (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 <a href=\"https:\/\/github.com\/reactjs\/react-rails#use-with-asset-pipeline\">README<\/a>). \u042f \u0441\u043c\u043e\u0433 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c <code>hello.jsx<\/code> \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u043d\u043e, \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043e\u0434\u0445\u043e\u0434, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0431\u044b \u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e webpacker \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 <code>gem \"webpacker\"<\/code>\u0432 <code>Gemfile<\/code>,  \u0437\u0430\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 react-rails, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 Arbre-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 React-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0444\u0430\u0439\u043b\u0430 <code>app\/javascript\/packs\/activeadmin.js<\/code>; \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/javascript\/packs\/activeadmin.js  \/\/ Support component names relative to this directory: var componentRequireContext = require.context(\"components\", true); var ReactRailsUJS = require(\"react_ujs\"); ReactRailsUJS.useContext(componentRequireContext);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435: \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 sprockets, Active Admin \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 pack, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     script src: asset_pack_path(\"activeadmin.js\")     react_component 'Hello', { name: 'David' }   end end<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0438 \u0431\u043e\u043b\u0435\u0435 \u00ab\u0447\u0438\u0441\u0442\u044b\u0435\u00bb \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 Active Admin:<\/p>\n<pre><code class=\"ruby\"># lib\/active_admin\/extra_headers.rb  module ActiveAdmin   module ExtraHeaders     def build_active_admin_head(*args)       super       return unless controller.respond_to?(:extra_headers)        within head do         controller.extra_headers.each do |extra_header|           text_node(extra_header)         end       end     end   end end<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"ruby\"># config\/initializers\/active_admin.rb  require_relative '..\/..\/lib\/active_admin\/extra_headers'  ActiveAdmin::Views::Pages::Base.send(:prepend, ActiveAdmin::ExtraHeaders)<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>app\/admin\/dashboard.rb<\/code>:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }   end    controller do     def extra_headers       [helpers.javascript_pack_tag('activeadmin')]     end   end end<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0445\u0430\u043a. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0443\u0434\u043e\u0431\u043d\u0435\u0435, \u043d\u043e \u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0441\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0435.<\/p>\n<h2>React-rails \u0438 Webpacker \u0432 \u0431\u043e\u044e<\/h2>\n<p>\u041f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043a \u0431\u043e\u0435\u0432\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c: \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 Typescript \u0438 \u0432\u043d\u0435\u0448\u043d\u044e\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 react-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c, \u0438 \u0432\u044b\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e .tsx-\u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 Typescript:<\/p>\n<pre><code class=\"bash\">rails webpacker:install:typescript yarn add -D @types\/react @types\/react-dom<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c \u043d\u0430\u0448 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0437 <code>.jsx<\/code> \u0432 <code>.tsx<\/code>:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react';  const Hello = ({name}: {name: string}) =&gt; {   return(     &lt;div&gt;Hello {name}!&lt;\/div&gt;   ); };  export default Hello;<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u043e\u0437\u044c\u043c\u0435\u043c <a href=\"https:\/\/github.com\/uber\/react-vis\">react-vis<\/a>. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">yarn add -D react-vis @types\/react-vis<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>app\/components\/javascript\/Plot.tsx<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ app\/components\/javascript\/Plot.tsx  import * as React from 'react'; import 'react-vis\/dist\/style.css'; import { XYPlot, LineSeries, LineSeriesPoint } from 'react-vis';  type Params = {   data: LineSeriesPoint[]; } const Plot = ({data}: Params) =&gt; {   return (     &lt;div className=\"Plot\"&gt;       &lt;XYPlot height={300} width={300}&gt;         &lt;LineSeries data={data} \/&gt;       &lt;\/XYPlot&gt;     &lt;\/div&gt;   ); };  export default Plot;<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"ruby\"># app\/admin\/dashboard.rb  ActiveAdmin.register_page \"Dashboard\" do   menu priority: 1, label: proc { I18n.t(\"active_admin.dashboard\") }    content title: proc { I18n.t(\"active_admin.dashboard\") } do     react_component 'Hello', { name: 'David' }     data = [       { x: 0, y: 5 },       { x: 2, y: 7 },       { x: 5, y: 8 },       { x: 7, y: 7 },       { x: 8, y: 3 },       { x: 6, y: 0 },       { x: 0, y: -5 },       { x: -6, y: 0 },       { x: -8, y: 3 },       { x: -7, y: 7 },       { x: -5, y: 8 },       { x: -2, y: 7 },       { x: 0, y: 5 }     ]     react_component 'Plot', { data: data }   end end <\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0451, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c React \u0432 Active Admin, \u0438 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0441\u0432\u0435\u0442\u043b\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435 \u0432\u0437\u043e\u0440\u043e\u043c, \u043f\u043e\u043b\u043d\u044b\u043c \u0440\u0435\u0448\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c) \u044d\u0442\u043e \u0437\u043d\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/535866\/\"> https:\/\/habr.com\/ru\/company\/domclick\/blog\/535866\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-317458","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317458"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/317458\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}