React-rails gem cannot find component - ruby-on-rails

I have my rails 6 app using asset pipeline. Now in one module, I want to integrate react and for that I installed webpacker. After rails webpacker:install and rails g react:install , I created one component in app/javascipt/components directory. From my rails view, I called react component which I just created like <%=react_component('name')%>. But in my browser I get these errors, ss is attached for reference.

Related

Ruby on Rails - node_modules file is too big

I am trying to learn ruby on rails. I created a new project with Rails 6.1.2.1 for this purpose but it took more than 5 minutes. The problem is after creating the project, it creates a huge 100Mb+ dir which is called node_modules with every possible node_package. This does not make sense as the default behavior. Am I actually missing something?
The node_modules are for your front-end stuff. Now Ruby on Rails supports webpacker with all goodies of NodeJS. It is already in .gitignore and it is normal behavior.
When you want to save your project, you can delete this folder and whenever you need you can use yarn install to get it back.
You can create rails app without installing webpacker
--skip-webpack-install option of Rails new. It still includes the webpackergem in the Gemfile and sets up the resulting project with webpacker configuration (only rails webpacker:install is not run).

how to enable ssr on Rails 6 app with webpacker and React

I'm guessing that since newly scaffolded Rails apps use webpacker, adding a gem like react rails would be an anti-pattern. that said, is there a canonical way to enable ssr on a rails app with react or would I need to run node as well for this?
I recently went through trying the 3 popular solutions:
Rails + Webpacker
Rails + Webpacker + react_on_rails
Rails + Webpacker + react-rails
react_on_rails opinion... It doesn't use integration tests that can use RSpec (Capybara) to combine both React + Rails environments. Both webpack and rails server are running via the foreman gem, which means you'd have to add another complex configuration to have RSpec integration tests that traverse both. There is also way too many settings that I was already configuring myself (Docker, Heroku, to name a couple...). The commit history the past year is also mostly doc changes (looking now this past couple weeks there has been some activity, though). Also it promotes a "Pro" edition, which kinda turned me off tbh.
react-rails is much more light-weight and was just easier to get working. The team is the official React team (reactjs.org). It "just worked" for me.
If you need a starting point, I'd recommend checking out this Rails starter kit that is built as a Rails + React setup:
https://github.com/patrickclery/dry-rails-react
Particularly these files:
babel.config.js
app/javascript/packs/application.js
app/javascript/packs/server_rendering.js
package.json
config/webpacker.yml
The gems are just another option, wondering why you see this gem in rails as an anti-pattern as there is a section in the react-rails gem documentation specific to webpacker. It clearly describes how to use the react-rails gem with Webpacker.
Here's another pretty up-to-date resource, which provides examples for
Webpacker
react-rails
react_on_rails
For webpacker it says:
All files in the new app/javascript/packs directory are compiled by Webpack.
For react-rails it says:
react-rails is the official React community gem for integrating React with Rails. The main benefit of using this gem is the react_component helper method which makes it easy to pass Rails data to components.
react-rails also gives you the option to continue using the default Rails asset pipeline to serve your React code, instead of using webpacker
For the third option react_on_rails it says:
The other most popular third-party gem for integrating React into Rails is the react_on_rails gem created by ShakaCode.
Similar to the react-rails gem, now that Rails already provides an easy way to use React via webpacker, you have to see if the stated benefits of the react_on_rails gem apply to your situation.

webpack server live reload

I'm building a react-rails app with rails 5.2.
react-rails-hot-loader is not compatible with rails 5.2, the live reloding would work with react_on_rails and I am trying to understand how to configure webpacker to live-reload
I had a read at the following issue
I run ./bin/webpack-dev-server --inline=false and my rails s in a separate terminal instance, but I can not display the site on webpacker localhost:3035/movies. The output in the browser is Cannot GET /movies
I just created the repository, do not know webpacker and would really appreciate any input.
webpacker 3.3.5 supports hot reloading
running ./bin/webpack-dev-server and rails s in a different terminal allows you to use hot reloading features
My understanding is that webpacker development server will provide the js, css and image assets to the rails server.
The application is available at localhost:3000 (from the rails server) for development with hot reloading. I started the webpacker dev server before my rails s
Some more article explains more in details how to configure the webpacker server
https://medium.com/statuscode/introducing-webpacker-7136d66cddfb
https://medium.com/rubyinside/hot-module-reloading-with-webpacker-b663643a60b1https://github.com/justisb/react_on_rails/blob/master/docs/additional-reading/hot-reloading-rails-development.md
https://learnetto.com/tutorials/hot-module-replacement

Ruby on Rails generators with new gemified plugin?

I'm attempting to create a new Rails 3 plugin gem which wraps around devise/devise_ldap_authenticatable for reusable drop in internal LDAP support.
I create the new plugin gem with:
rails plugin new <gem_name>
I then add the devise/devise_ldap_authenticatable gems to the .gemspec file and run bundle
In the devise instructions it says to generate the required files using its generators:
rails generate devise:install
rails generate devise MODEL
However, in the directory where the plugin is generated I don't seem to be able to run rails generate. Most gem plugin tutorials instruct you to just create the files manually. Am I better off starting a new rails project, following the instructions in the temp project, then copying the files over to the plugin manually? Is there something that I'm missing? Can I run the generator script from the dummy instance? What is the standard practice in this use case?
In the end, I opted to forgo wrapping devise_ldap_authenticatable due to its relative simplicity.
The answer that I would go with in the future is to just to move files from a throwaway project.

Rails 2.x app on RubyMine 3.1

i've upgraded to rubymine 3.1 and now rubymine take all project as rails 3 project, but the mine are not. Does anybody of you face this problem. Ruby mine fires up this message, when i try to run application
Run configuration error: Rails 2.x launcher found instead of Rails 3.x one. You need '/script/rails'
script to launch Rails server. Please update server launcher according to Rails 3.x documentation
My final state is i can run rails 2.x app server from rubymine
Do you know how to achieve that?
I had this problem using Rails 2.3 and RubyMine 3.1 -- my solution was to look at the project settings (File -> Settings) and select Ruby SDK and Gems. Look through your attached rails gems. I had both rails 2.x and rails 3.x gems attached to my project.

Resources