Tag: react rails

如何将关联加载到实例变量?

在模型中我有: class CalendarItem < Resource belongs_to :schedule has_many :people has_many :documents acts_as_list scope: :schedule, column: :visual_position validates :schedule, :title, presence: true end 然后在控制器中: class ScheduleController < ApplicationController def show @calendar_items = CalendarItem.where(schedule: @schedule).includes(:people, :documents) end … end 在视图中,我正在使用react-rails渲染react_component(但这应该有所不同): = react_component(‘CalendarItemsList’, calendar_items: @calendar_items) 但是它不会将关联数据传递给视图(react_component),只传递主模型。 我以前经历过这种情况,没有反应前端,也没有用。 可能有什么不对?

React-Rails – 入门问题

我正在试图弄清楚如何在我的Rails 5 gem中使用react-rails。 目前,我正在尝试按照本文中的教程进行操作。 https://medium.com/technically-speaking/isomorphic-reactjs-app-with-ruby-on-rails-part-1-server-side-rendering-8438bbb1ea1c#.iwd44r60v 我目前无法获取要呈现的页面。 我使用app_roles而不是post,但除此之外我还按照教程中显示的步骤操作。 我的app / assets / javascripts / components文件夹中有两个文件。 app_role.js.jsx有: var AppRole = React.createClass({ render: function() { return ( ); } }); var AppRoleHeader = React.createClass({ render: function() { return ( {this.props.app_role.title} By {this.props.app_role.title} – {this.props.app_role.created_at} ); } }); var AppRoleContent = React.createClass({ render: function() { return ( {this.props.app_role.display_name} ); […]

使用’material-ui’和react-rails gem?

我想在我的Rails 4应用程序中使用material-ui组件库。 我目前正在使用react-rails gem将.jsx编译添加到资产管道。 我在gemfile中通过rails-assets添加了material-ui,如下所示: source ‘https://rails-assets.org’ do gem ‘rails-assets-material-ui’ end 我在我的application.js文件中需要这样的库: //= require material-ui 但是我一直收到错误“找不到文件’材料-ui”。 如何使用react-rails gem在我的Rails应用程序中使用material-ui组件库?

使用webpack从react-rails应用程序中的node_modules加载字体

我有一个使用webpacker设置的react-rails应用程序。 我正在尝试使用node_modules中的字体加载font-awesome-pro。 我认为这是一项微不足道的任务,但我似乎无法找到关于如何做到这一点的任何好的文档。 这是我到目前为止: package.json依赖项: “dependencies”: { “@rails/webpacker”: “3.5”, “babel-preset-react”: “^6.24.1”, “bootstrap”: “^4.1.3”, “prop-types”: “^15.6.2”, “react”: “^16.5.2”, “react-dom”: “^16.5.2”, “react-slick”: “^0.23.1”, “react_ujs”: “^2.4.4”, “slick-carousel”: “^1.8.1”, “tachyons-z-index”: “^1.0.9” }, “devDependencies”: { “@fortawesome/fontawesome-pro”: “^5.2.0”, “babel-plugin-transform-class-properties”: “^6.24.1”, “babel-preset-env”: “^1.7.0”, “file-loader”: “^2.0.0”, “path”: “^0.12.7”, “webpack-dev-server”: “2.11.2” } file.js: var path = require(‘path’); module.exports = { test: /\.(woff(2)?|eot|otf|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, exclude: path.resolve(__dirname, […]

如何将此React库与React-Rails一起使用

我发现了这个: https://github.com/ssorallen/turbo-react 我喜欢它的function,我对我如何在目前使用React-Rails gem的 Rails项目中使用此代码感到困惑 我很困惑在哪里放置代码,以便我可以使用React Rails将其读入我的Rails gem。 如果我将主JS文件粘贴到我的vendor / assets文件夹中,我收到以下消息: Uncaught ReferenceError: global is not defined 我知道我从根本上误解了如何将这种JS文件包含到我的Rails项目中。