Search code examples
react.rb

Errors when integrating reactive-record with react-rails


I'm having trouble adding reactive-record to my project.

Gemfile:

gem 'rails', '4.2.4'

gem 'bootstrap-sass' #, '~> 3.3.6'
gem 'sprockets-rails'
source 'https://rails-assets.org' do
  gem 'rails-assets-tether', '>= 1.1.0'
end

gem 'pg'

gem 'reactive-ruby', '~> 0.7.28'
gem 'react-rails', '~> 1.3.1'
gem 'opal'
gem 'opal-browser'
gem 'opal-rails', '~> 0.8.0'
gem 'opal-jquery'     # a clean interface to jQuery from your ruby code

gem 'reactive-router' # a basic SPA router

# gem 'reactive-record'

# ... additional Rails boilerplate below ...

When I run the application as-is, it renders the React component just fine. When I uncomment gem 'reactive-record', I get a NoMethodError in my controller: undefined method 'path' for nil:NilClass. Here is my simple controller:

home_controller.rb:

class HomeController < ApplicationController
  def show
    render_component
  end
end

render_component is the line that triggers the error.

Any clue what the problem is? I feel like I'm missing something obvious, but I've been troubleshooting for two days.


Solution

  • The installation of reactrb and reactiverecord has been proven more difficult than it should have before.

    That's why I created a generator to install everything: https://github.com/loicboutet/reactive-rails-generator

    You should be able to get up and running by adding to your gem file : gem 'reactive_rails_generator'

    Then do a `bundle install``

    and finally : rails g reactrb:install --all bundle update

    Will install you reactrb, reactive-record and reactive-router.