Skip to content

Instantly share code, notes, and snippets.

@fk2000
Last active January 26, 2018 04:07
Show Gist options
  • Save fk2000/0b9ff6a40f5f484aa77777903e3b5ffc to your computer and use it in GitHub Desktop.
Save fk2000/0b9ff6a40f5f484aa77777903e3b5ffc to your computer and use it in GitHub Desktop.
rails, react, hypernovaの環境構築からのHello World! ref: https://qiita.com/fk_2000/items/e8d6709e3a846be9ce1f
<!DOCTYPE html>
<html>
<head>
<title>HypernovaGettingStartedWithRails</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>
# ruby/rails(rbenv)
$ rbenv -v
rbenv 1.1.1-28-gb943955
$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
$ gem -v
2.6.13
$ rails -v
Rails 5.1.4
# node/npm(nvm)
$ nvm --version
0.33.8
$ node -v
v7.9.0
$ npm -v
4.2.0
$ rails new hypernova-getting-started-with-rails
% bin/rails server
<div data-hypernova-key="MyComponentjs"></div>
<script type="application/json" data-hypernova-key="MyComponentjs"><!--{"name":"Hypernova"}--></script>
$ rails generate controller welcome index
$ bundle install
Installing browserify-rails 4.2.0
% npm init -y
% npm install
gem "hypernova"
const hypernova = require('hypernova/server');
hypernova({
devMode: true,
getComponent(name) {
if (name === 'MyComponent.js') {
return require('./app/assets/javascripts/MyComponent.js');
}
return null;
},
port: 3030,
});
require 'hypernova'
Hypernova.configure do |config|
config.host = 'localhost'
config.port = 3030
end
<%= render_react_component('MyComponent.js', name: 'World') %>
var React = require('react');
var renderReact = require('hypernova-react').renderReact;
function MyComponent(props) {
return React.createElement('div', {
onClick: function () {
alert('Click handlers work.');
},
}, 'Hello, ' + props.name + '!');
}
module.exports = renderReact('MyComponent.js', MyComponent);
{
"name": "hypernova-getting-started-with-rails",
"private": true,
"dependencies": {
"hypernova": "^1.0.0",
"hypernova-react": "^1.0.0",
"react": "^15.1.0",
"react-dom": "^15.1.0"
},
"devDependencies": {
"browserify": "^13.0.1",
"browserify-incremental": "^3.1.1"
},
"description": "This README would normally document whatever steps are necessary to get the application up and running.",
"version": "1.0.0",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "fk2000",
"license": "MIT"
}
class WelcomeController < ApplicationController
- around_filter :hypernova_render_support
+ around_action :hypernova_render_support
def index
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment