My rails 7 app is getting an error unknown format for format.js So then what do I need to install, rails-ujs, jquery, ... which npm package or which rails gem I built this site with jsbundling esbuild and cssbundling bootstrap
You should be able to listen to a format.js request with something like this in your controller:
respond_to do |format|
format.js
end
Then you would probably want to have a template with the js.erb template in the views folder.
But be aware that this isn't the preferred way in Rails 7.
Format.js responses was in the Rails-UJS days the way to go.
These days you can use TurboStream for asynchron request.
If you can't use Turbo, you have to install the #rails/ujs npm package and initialize it with:
import Rails from '#rails/ujs';
Rails.start();
Related
I am trying to deploy on Heroku RTesseract feature to read text on image.
I add the gem into the Gemfile
gem 'rtesseract'
I implemented the feature into the PagesController#home (sure it is dirty but it is for testing before adding to my real app)
class PagesController < ApplicationController
def home
image = RTesseract.new('https://www.drillster.com/info/img/screenshot-ticket-received.en.png')
#result = image.to_s
end
end
It is working well on http://localhost:3000/. I can see the text printing of the page
When I deploy on Heroku, I have add the following buildpacks :
heroku buildpacks:set heroku/ruby
heroku buildpacks:add https://github.com/pathwaysmedical/heroku-buildpack-tesseract
When I start my application on Heroku, I can see the error :
Tesseract::Error (Cannot open input file:
https://www.drillster.com/info/img/screenshot-ticket-received.en.png)
The error is raising when the code executed the line #result = image.to_s
If someone has already solve this issue, it will be really nice to help me !
Thanks in advance for your help & reading !
So it looks like they added libcurl to get images from URLS in this commit here:
https://github.com/tesseract-ocr/tesseract/commit/286d8275c783062057d09bb8e5e6607a8917abd9
That was in OCT 2019
Looking in the changelog here:
https://github.com/tesseract-ocr/tesseract/blob/master/ChangeLog
We see that version 2018-10-29 - V4.0.0
the version in that buildpack is:
https://github.com/pathwaysmedical/heroku-buildpack-tesseract/blob/master/tesseract-ocr-4.0.tar.gz
So I'm guessing that the buildpack version doesn't support getting the image via URL. I bet when you run it locally you have 4.1 and not the older 4.0?
You could fork that buildpack, get the latest source and compile it with libcurl, or you could try download it to a tempfile and then pass that tempfile location to the library. Though that's not awesome for a variety of reasons and you probably want to delete it when you're done.
If I'm wrong about the version numbers please let me know.
If you install httparty, you could do something like this to test it
url = 'https://www.drillster.com/info/img/screenshot-ticket-received.en.png'
File.open("/tmp/test_file.jpg", "wb") do |f|
f.write HTTParty.get(url).body
end
image = RTesseract.new('/tmp/test_file.jpg')
image.to_s
# "Requested ticket\n\nTo make this test, a user must have a ticket....."
I am creating a new rails6 application, and I need to host multiple Reactjs applications inside of this rails app.
So I will have an 'admin' section that will be React based.
On the customer facing website it will be regular rails erb/html templates, but I have one area that needs to be react.
How can I have multiple Reactjs applications that can also share components between each other?
How can I have multiple Reactjs applications that can also share
components between each other?
You can use the package Bit which lets you share components between your projects.
Quote from docs:
Bit makes it easy to share and manage components between projects and
apps at any scale.
It lets you reuse individual components across projects.
See documentation, and GitHub repo for details.
There are few ways todo this, personally I use this one.
My current ongoing project also, front-end based on erb and admin panel using ReactJS.
if your app not supporting webpack, then suggesting to install it.
1) install gem 'webpacker'
Also update coffee-rails, for rails6. gem 'coffee-rails', '~> 5.0.0'
2) bundle install
3) bundle exec rails webpacker:install
4) bundle exec rails webpacker:install:react
Viola: Webpacker now supports react.js 🎉
Once after installation, you will see app/javascript/packs/application.js & hello_react.jsx
Create routes and controllers as usually, just make sure to create and use specific layout under app/views/layouts/admin.html.erb
# sample - controllers
class AdminController < ApplicationController
layout 'admin'
end
class SampleController < AdminController
def index
end
end
# create routes for this action!
# view/layouts/admin.html.erb
<head>
<%= javascript_pack_tag 'application' %>
</head>
After all, check browser console it will be logged Hello World from Webpacker
from app/javascript/packs/application.js
Everything else as default npm installations and etc.
To start the rails server with webpack
rails s & ./bin/webpack-dev-server
I have install Spree ecommerce following this link
https://guides.spreecommerce.org/developer/getting_started_tutorial.html
all are work but canot find out the backend and frontend folder.
Can anyone teach me how to show or find out all the controller in Back end and front end
Since Spree 3.4 you can copy views (turned on by default).
rails g spree:install --migrate=false --sample=false --seed=false --copy_views=false
If you have an older version then you have to copy views from GitHub Spree repo.
I used Helicon Zoo to set up a rails application on a Windows Server 2008 machine.
My problem is downloading files above 400MB.
In my rails app I use the following to send files to a client:
app/controllers/hosted_files_controller.rb
class HostedFilesController < ApplicationController
before_filter :authenticate_user!
around_filter :catch_not_foun
def download
#footprint = UserAbility.new(current_user).footprints.find(params[:id])
send_file path
end
private
def path
if #footprint.subpath?
#path = "#{HOSTED_FILES_PATH}\\#{#footprint.subpath}\\#{#footprint.filename}"
else
#path = "#{HOSTED_FILES_PATH}\\#{#footprint.filename}"
end
end
def catch_not_found
yield
rescue ActiveRecord::RecordNotFound
recover_and_log "We couldn't find that record.", "No record found using the id (#{params[:id]})"
rescue ActionController::MissingFile
recover_and_log "We couldn't find the file on our server.", "The file was not found at the following path: #{#path}"
end
def recover_and_log (displayed, logged)
logger.info "!!! Error: #{logged}"
redirect_to root_url, alert: displayed
end
end
I have config.action_dispatch.x_sendfile_header commented out in the production.rb file since I am not using Apache or Nginx.
This works great for all the files on the server that are below ~400MB. After I get above it, I get a 500 internal server error from Helicon Zoo that says the following:
Helicon Zoo module has caught up an error. Please see the details below.
Worker Status
The process was created
Windows error
The pipe has been ended. (ERROR CODE: 109)
Internal module error
message: ZooApplication backend read Error.
type: ZooException
file: Jobs\JobBase.cpp
line: 566
version: 3.1.98.508
STDERR
Empty stderr
Does anyone have any idea what is going on? I'm at a loss.
I've tried:
increasing the buffer_size on send_file (didn't work)
play around with memory settings in IIS for the application pool (didn't work)
change x_sendfile_header to X-Sendfile and X-Accel-Redirect (didn't work)
I'm considering trying to install Apache on the Windows Server and using the x_sendfile_header to offload sending the file to Apache, but I'm afraid of messing up the already (almost) working application.
Does anyone have any ideas of how to fix this?
By default with current version of Helicon Zoo Ruby applications are installed as FastCGI Ruby Rack connector. Since FastCGI protocol is a blocking protocol it may have some limitations on request timeout or request max size. If you need to send large files I suggest you to go "Ruby 1.9 Rack over HTTP with Thin" route instead. I suppose you've been following Ruby on Rails (2.3.x and 3.x.x) instruction. Now just follow additional steps from Ruby Rack over HTTP with Thin instruction, like running "gem install thin" command and editing web.config as follows:
In the < handlers> section comment out two lines that follows
< !-- Ruby 1.9 over FastCGI -->
Uncomment two lines that follows
< !-- Ruby 1.9 over HTTP, using Thin as a back-end application server -->
In the <environmentVariables> section uncomment line
< !-- Use this APP_WORKER with HTTP Ruby engine and Thin. Thin need to be installed.
< add name="APP_WORKER" value="GEM_HOME\bin\thin start" />
Another solution, since you already using Helicon products, would be installing Helicon Ape that provides support for X-Sendfile HTTP header (see documentation) header as in Apache and is free for several sites per server. This solution would be even better since low level WinHTTP code will be used to send data, which will decrease load to the server and improve response speed.
I'm trying to deploy a Rails app to Tomcat with a war file generated by Warbler. The war file deploys to /myproject-rails-gui without any problems but, when I try to access a page on the app, I'm getting:
ArgumentError: wrong number of arguments (1 for 0)
send at org/jruby/RubyKernel.java:2097
Railtie at /home/myproject/apache-tomcat-7.0.22/webapps/myproject-rails-gui/WEB-INF/gems/gems/actionpack-3.0.10/lib/action_controller/railtie.rb:54
It's failing when it tries to set relative_url_root. There are other Stack Overflow articles that (correctly) point out that relative_url_root is deprecated and you should set the RAILS_RELATIVE_URL_ROOT environment variable instead.
From the Rails project on GitHub
module ActionController
class Base
# Deprecated methods. Wrap them in a module so they can be overwritten by plugins
# (like the verify method.)
module DeprecatedBehavior #:nodoc:
def relative_url_root
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root is ineffective. " <<
"Please stop using it.", caller
end
def relative_url_root=
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root= is ineffective. " <<
"Please stop using it.", caller
end
I haven't had any luck figuring out how to do that using Warbler and Tomcat, though. Any suggestions? For what it's worth, the app works fine when I run it in the root context.
My environment:
Warbler 1.3.2
Tomcat 7.0.22
JRuby 1.6.5
Rails 3.0.10
After a lot of digging, it looks like this particular exception was being caused by a missing parameter in ActionController::DeprecatedBehavior.relative_url_root= in Rails v3.0.10. Miguel, your issue might be related but, if you're seeing it in Rails v3.1.1, then it's slightly different. The file that I had to modify to fix it doesn't exist in v3.1.1.
I filed issue 3645 in the Rails project on Github, fixed it in a fork, and issued a pull request to them. Hopefully this will be fixed in a new release of Rails 3.0.
In the meantime, if you want to use my fixed version, it's available at https://github.com/mhuffnagle/rails/tree/3-0-stable.