Moving devise model to React.rb public directory calls method missing

102 views Asked by At

I'm trying to use Devise with React.rb, so I thought I'll move my user model to the public directory to be able to edit it through React, however I get this error:

ActionView::Template::Error(User.devise(database_authenticatable,registerable,recoverable,rememberable,trackable,validatable) (called class method missing)):
1: <%= react_component @component_name, @render_params, { prerender: !params[:no_prerender] } %>
1

There are 1 answers

0
Mitch VanDuyn On BEST ANSWER

You probably have some devise specific macros in your user model.

for example if you user model looks like this:

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable
  # etc...
end

then you will need to insure the devise call only runs on the server like this:

class User < ActiveRecord::Base

  unless RUBY_ENGINE=='opal'
    devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable
  end
  # etc...
end

Reactive-Record stubs and proxies all the standard active-record macros like scope, and belongs_to on the client. However it doesn't know what the devise method means, so wrapping it in unless RUBY_ENGINE=='opal will prevent this from being called on the client.

FYI I added an issue https://github.com/catprintlabs/reactive-record/issues/17 to reactive-record to cover this...