railsにreactでHelloReactしてみた
Gemfileに以下追記
gem 'react-rails'
reactのためにいろいろ準備
$ bundle install --path ./vendor/bundle/ # reactに必要なディレクトリを作る $ rails g react:install # コンポーネントの追加 $ rails g react:component Test(component name) # HelloWorldを出させてみる $ vim app/assets/javascripts/components/test.js.jsx var Test = React.createClass({ render: function() { return ( <div>Hello React!!</div> ) } }); # Viewを作成 $ rails g controller test index # viewにコンポーネントの呼び出し追記 $ vim app/views/test/index.html.erb <%= react_component('Test') %> # ルーティングに追加 $ vim config/routes.rb root 'test#index'
はろーわーるど!
はろーりあくと!