webpack server live reload - ruby-on-rails

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

Related

how to execute the rails application in rails 2.3.14?

I am new to the rails programming. I was building my first rails application.
In internet I was searched how to run the rails application in rails 2.3.14 version. But I did not get the answer.
I know how to start the server. But I don't know how run the rails application.
Can anyone please explain me how to run the rails application in 2.3.14 version.
You start a server in Rails 2.3 with:
./script/server start
That starts a local server in development mode, browse to http://localhost:3000 to see your application.
You might want to have a look at the other scripts in the scripts folder too, you will find a subset of modern rails commands. Like
./script/console
to open the Rails console.
But I wouldn't recommend to learn Rails with a 2.3 application. 2.3 has many differences to modern Rails 4.2 or 5.0 application.

WEBrick Server not running with rails 5.0.0.rc1

I'm new to Ruby on Rails, and am trying to set up a basic, local web server in order to dive into all the framework has to offer. I've installed rails using
gem install rails
and have everything seeming to work. However, I also downloaded rails 5.0.0.rc1. When I call to boot up the server with
rails s
or
bin/rails server
it just ends up with a blank screen on http://localhost:3000. Does this have anything to do with the installation of rails 5.0.0.rc1? Why am I just getting a blank screen and not the default information page which signals that it is working?

404 not found error for assets in rails 4 production enviroment

I am new to rails from java enviroment. I have few confusions in asset pipeline with rails 3 to 4.
Currently I am in rails 4.2.5
I created a sample app on my local environment.
I created a new js from inside app/assets/javascripts and referencing it from the view , everything seems to working fine on my local environment.
After this I thought to test with production env how it works. Here are the steps I did.
RAILS_ENV=production rake assets:clean assets:precompile [All the files created public/assets]
Started the server in production mode rails server -e production
Now when i browsed the page I am getting this error,
"NetworkError: 404 Not Found - http://localhost:3000/assets/application-c5c431cb7c0a202f831a634922aaf1d536712002ae74334fb03ba4698b32b84c.js" in firebug.
When searched few threads , they suggest to add config.assets.compile = true. But I do not think so this is what the solution is, as it slows down the app.
Please help.
By default Rails4 will return a 404 if an asset is not handled via an
external proxy such as Nginx.
- https://github.com/heroku/rails_serve_static_assets
I suggest you have a look at the rails_12factor gem, which includes the rails_serve_static_assets gem which will allow your Rails app to serve static assets (like your .js file).
Edit:
You may not need a gem for this (though I've not tried it):
config.serve_static_files configures Rails itself to serve static
files. Defaults to true, but in the production environment is turned
off as the server software (e.g. NGINX or Apache) used to run the
application should serve static assets instead. Unlike the default
setting set this to true when running (absolutely not recommended!) or
testing your app in production mode using WEBrick. Otherwise you won't
be able use page caching and requests for files that exist regularly
under the public directory will anyway hit your Rails app.
- http://guides.rubyonrails.org/configuring.html
In Rails 5, this config method has been renamed to config.public_file_server.enabled, the rails_serve_static_assets gem handles the correct naming depending on version.

While using refinery ruby (Rack) application could not be started

I just installed a new rails 3 application on ruby 1.9.2 for the first time using Refinery CMS.
Everything went well using refinerycms to install the application, but passenger is having issues with the application.
Passenger says Rack can not start gives me error:
"No such middleware to insert after: ActionDispatch::Static"
I am running several other rails applications on my server using passenger without trouble; although none of those applications are using refinerycms.
Help much appreciated as this is a project in a class I'm taking and have very limited time to complete the scope of this project, would be awesome to get started.
In your config/environments/production.rb file you have to specify:
config.serve_static_assets = true
This enables ActionDispatch::Static and is a requirement of Refinery CMS.

Using Gem Dependencies if a server is 2.0 instead of 2.1

At work for internal Rails applications, the server is running Rails 2.0.4 and Ruby 1.86. As far as I know, that's not going to change anytime soon and I have no control over it. I was going to try and test this out between a couple of computers and was curious if anyone knew what would happen.
Being the server is on 2.0.4, I'd like to build Rails 2.3.5 applications for that server if at all possible. From what I understand so far, it won't be a problem if I freeze gems and upack dependancies. Does that sound right?
Also, the internal work server has no gems beyond what Rails installs. What I'm wondering is, if I can successfully run a 2.3.5 application on the 2.0.4 server, can I also use extra gems and unpack those to use even though the server doesn't have them? I know that it was version 2.1 that introduced Gem Dependencies so would a 2.3.5 Rails app running on a 2.0.4 server be able to use required gems that are unpacked into an application?
One of the worst things with this situation is even if the above stuff works, the server being on 1.86 would exclude me from using a lot of really cool gems that require Ruby 1.87 (like Formtastic).
Thanks
You can manually specify the version of Rails being used in the application in the conf/environment.rb file with the RAILS_GEM_VERSION variable.
You won't be able to gems that aren't installed on your server because the application won't be able to find the libraries.
I went ahead and did the leg work to test this out. If this helps anyone else:
Rails 2.3.5 will run fine on a 2.0.x server.
With Rails 2.1 or above, you can unpack gems and your app will work on a 2.0.x server (lower version server). These are the steps I took in order. The only thing unique here is the Rack version is specific to Rails 2.3.5 (and below). In version 2.3.6 and up they switched to rack 1.1. I'm sticking to 2.3.5 because of the Rack issues with 2.3.6 and up, like broken multipart uploads).
(inside your application directory).
rake rails:freeze:gems
rake gems:unpack:dependencies
(Create a Gems Folder in the vendor folder if it's not there)
(Navigate inside the gems folder: your_app\vendor\gems)
gem unpack rack -v="1.0.1"
(There should now be a folder called "rack-1.0.1" inside the gem folder)
(Navigate back out to your application root folder)
rake gems:refresh_specs
I tested this out using the authlogic gem - moving the project over to a spare laptop that only had Rails 2.0.4 installed and no other gems (except MySQL and Mongrel). The only thing I'm not sure about yet is if a gem that requires a script file be run for installation after the gem file (like Simple Forms) will work. I'm going to test that out next when I get time.

Resources