3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails5でreactとreduxをinstall

Posted at

reduxをRailsで使えないかなぁ。って調べていて、
https://github.com/rackt/redux/tree/master/examples/counter
http://redux.js.org/
試してみたので、メモ程度にのこしておきます。

※以下のバージョンをinstallしました。
rails 5.0.0
redux 3.5.2
react-rails react-rails
react 15.3.0

browserify-railsのインストール

Gemfileに以下を記述
gem 'browserify-rails'

config/application.rbに以下を記述
config.browserify_rails.commandline_options = '-t babelify'

bundle install
npm install --save-dev browserify
npm install --save-dev browserify-incremental

reduxのインストール

npm install --save react
npm install --save redux
npm install --save react-redux
npm install --save redux-thunk

※react-railsでもできるっぽいので、不要かも...。

react-railsのインストール

gem 'react-rails'

reactのファイル生成

rails g react:install

create  app/assets/javascripts/components
create  app/assets/javascripts/components/.gitkeep
insert  app/assets/javascripts/application.js
insert  app/assets/javascripts/application.js
insert  app/assets/javascripts/application.js
create  app/assets/javascripts/components.js

components.jsの修正

window.React = require('react');
window.React = require('react-dom');
window.Root  = require('./components/containers/Root.js');

<%= react_component('Root') %>
あとは上記をviewに追加する。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?