how to disable turbo links completely from rails - sprockets

I've gone through quite a few posts and turbolinks documentation, and I think I haven't quite got it yet. I'm trying to completely turn off turbolinks in rails 5 application. Here's how I went about it
Removed gem 'trubolinks'
removed all occurrences of //=require turbolinks from application.js
removed data-turbolinks-track from stylesheet_link_tag and javascript_include_tag
The application.html.erb now looks like this
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Website" %></title>
<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Website" %>">
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= stylesheet_link_tag params[:controller] %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag :modernizr %>
<%= javascript_include_tag params[:controller] %>
<%= if(params[:action].eql?'contact')
javascript_include_tag 'https://www.google.com/recaptcha/api.js?onload=vcRecaptchaApiLoaded&render=explicit' , async: 'async', defer: 'defer'
end
%>
<%= csrf_meta_tags %>
</head>
<body data-turbolinks='false'>
...
</body>
</html>
the application.js file:
//= require jquery
//= require jquery_ujs
//= require lodash
//= require bootstrap-sprockets
//= require jquery.sticky
and application.css
#import "bootstrap-sprockets";
#import "bootstrap";
#import "font-awesome-sprockets";
#import "font-awesome";
#import "normalize-rails";
#import "animate";
....
/* other css stuff */
I was thinking using data-turbolinks=false on body tag should help disable it for all pages in this layout. But that hasn't helped, the pages fail to load with error
Sprockets::FileNotFound at /
couldn't find file 'turbolinks' with type 'application/javascript'
Checked in these paths:
/Users/anadi/Code/website/app/assets/config
/Users/anadi/Code/website/app/assets/fonts
/Users/anadi/Code/website/app/assets/images
/Users/anadi/Code/website/app/assets/javascripts
at this line on the home page
<%= image_tag("pages/home/xyz_logo.png", class: "img-responsive", alt: "Customer") %>
if I look at the stack trace, ActionView invariably depends on turbolinks:
sprockets (3.7.0) lib/sprockets/directive_processor.rb:182:in `rescue in block in process_directives'
sprockets (3.7.0) lib/sprockets/directive_processor.rb:179:in `block in process_directives'
sprockets (3.7.0) lib/sprockets/directive_processor.rb:178:in `process_directives'
sprockets (3.7.0) lib/sprockets/directive_processor.rb:83:in `_call'
sprockets (3.7.0) lib/sprockets/directive_processor.rb:68:in `call'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.7.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.7.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.7.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
sprockets (3.7.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.7.0) lib/sprockets/bundle.rb:23:in `block in call'
sprockets (3.7.0) lib/sprockets/utils.rb:196:in `dfs'
sprockets (3.7.0) lib/sprockets/bundle.rb:24:in `call'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.7.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.7.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.7.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
sprockets (3.7.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.7.0) lib/sprockets/base.rb:66:in `find_asset'
sprockets (3.7.0) lib/sprockets/base.rb:73:in `find_all_linked_assets'
sprockets (3.7.0) lib/sprockets/manifest.rb:134:in `block in find'
sprockets (3.7.0) lib/sprockets/manifest.rb:133:in `find'
sprockets-rails (3.1.1) lib/sprockets/railtie.rb:50:in `precompiled_assets'
sprockets-rails (3.1.1) lib/sprockets/railtie.rb:35:in `asset_precompiled?'
sprockets-rails (3.1.1) lib/sprockets/railtie.rb:250:in `block (3 levels) in <class:Railtie>'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:342:in `precompiled?'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:346:in `raise_unless_precompiled_asset'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:313:in `asset_path'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:85:in `block in resolve_asset_path'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:225:in `block in resolve_asset'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:224:in `resolve_asset'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:84:in `resolve_asset_path'
sprockets-rails (3.1.1) lib/sprockets/rails/helper.rb:74:in `compute_asset_path'
actionview (5.0.0) lib/action_view/helpers/asset_url_helper.rb:144:in `asset_path'
actionview (5.0.0) lib/action_view/helpers/asset_url_helper.rb:311:in `image_path'
actionview (5.0.0) lib/action_view/helpers/asset_tag_helper.rb:214:in `image_tag'
It looks like sprockets still expects turbolinks js or the image_tag url expects it. I don't want to end-up adding a data: { turbolinks: false } on every link or image. How to get this working?

Remove the gem 'turbolinks' line from your Gemfile.
Remove the //= require turbolinks from your app/assets/javascripts/application.js.
Remove the two "data-turbolinks-track" => true hash key/value pairs
from your app/views/layouts/application.html.erb.

I was doing it wrong perhaps, re-enabled all of it, added data-turbolinks-track => true also, and preserved <body data-turbolinks='false'>. It works as expected now without throwing errors.

Related

Issues converting database from sqlite to postgres

Recently deployed a new webapp to Heroku. The app was prototyped using SQLite and am having difficulty with the database implementation in Heroku which uses postgresql. Namely, I am receiving this error and I am not sure how to troubleshoot:
2020-05-10T13:22:15.250905+00:00 app[web.1]: HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
2020-05-10T13:22:15.250906+00:00 app[web.1]:
2020-05-10T13:22:15.250906+00:00 app[web.1]: [SQL: SELECT count(*) AS count_1
2020-05-10T13:22:15.250907+00:00 app[web.1]: FROM (SELECT favorites.fav_id AS favorites_fav_id, favorites.user_id AS favorites_user_id, favorites.post_id AS favorites_post_id, favorites.fav_date AS favorites_fav_date
2020-05-10T13:22:15.250907+00:00 app[web.1]: FROM favorites
2020-05-10T13:22:15.250907+00:00 app[web.1]: WHERE favorites.post_id = %(post_id_1)s) AS anon_1]
2020-05-10T13:22:15.250908+00:00 app[web.1]: [parameters: {'post_id_1': 1}]
2020-05-10T13:22:15.250908+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/f405)
2020-05-10T13:22:15.255615+00:00 app[web.1]: 10.31.64.150 - - [10/May/2020:13:22:15 +0000] "GET /home HTTP/1.1" 500 290 "https://benchofthoughts.herokuapp.com/post/new" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36"
2020-05-10T13:22:15.254572+00:00 heroku[router]: at=info method=GET path="/home" host=benchofthoughts.herokuapp.com request_id=1eed4376-3745-471d-8623-70217574197a fwd="47.20.85.233" dyno=web.1 connect=1ms service=31ms status=500 bytes=767 protocol=https
From reading this question and this question it looks like the query is trying to use a string instead of an int as the key to pull the relevant data, but this seemed to work fine using the prototype database. I am using SQLAlchemy for the queries so I assume the right variable types are implicitly being used, but I am not sure.
Can someone point me in the right direction to address this error?

CORS trouble between Sinatra and AngularJS

I'm in troubles with a very basic web app. Here are my files:
public/index.html
<!DOCTYPE html>
<html lang="en" data-ng-app>
<body>
<div data-ng-controller="PlayersCtrl">
<div data-ng-repeat="player in players">
{{player.id}}
</div>
</div>
<script src="/angular.min.js"></script>
<script src="/players.js"></script>
</body>
</html>
public/players.js
function PlayersCtrl($scope, $http) {
$scope.players = [];
$http({
method: 'GET',
url: 'http://localhost:9292/hi'
}).success(function(data) {
$scope.players = data;
});
}
client.rb
require 'sinatra'
get '/' do
headers 'Access-Control-Allow-Origin' => '*'
headers 'Access-Control-Allow-Headers' => 'Authorization,Accepts,Content-Type,X-CSRF-Token,X-Requested-With'
headers 'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS'
send_file File.join(settings.public_folder, 'index.html')
end
api.rb
require 'sinatra'
require 'json'
get '/hi' do
headers 'Access-Control-Allow-Origin' => '*'
headers 'Access-Control-Allow-Headers' => 'Authorization,Accepts,Content-Type,X-CSRF-Token,X-Requested-With'
headers 'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS'
[id: 1, name: "Bob"].to_json
end
To me, this seems good. Then, I start the servers:
Starting api.rb
$ ruby api.rb -p 9292
[2013-03-07 23:57:43] INFO WEBrick 1.3.1
[2013-03-07 23:57:43] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin12.2.0]
== Sinatra/1.3.5 has taken the stage on 9292 for development with backup from WEBrick
[2013-03-07 23:57:43] INFO WEBrick::HTTPServer#start: pid=62634 port=9292
Starting client.rb
$ ruby client.rb
[2013-03-07 23:57:40] INFO WEBrick 1.3.1
[2013-03-07 23:57:40] INFO ruby 2.0.0 (2013-02-24) [x86_64-darwin12.2.0]
== Sinatra/1.3.5 has taken the stage on 4567 for development with backup from WEBrick
[2013-03-07 23:57:40] INFO WEBrick::HTTPServer#start: pid=62610 port=4567
But when I go with a browser on localhost (port 4567), I have the following logs:
api.rb logs
127.0.0.1 - - [07/Mar/2013 23:57:46] "OPTIONS /hi HTTP/1.1" 404 442 0.0015
localhost - - [07/Mar/2013:23:57:46 CET] "OPTIONS /hi HTTP/1.1" 404 442
http://localhost:4567/ -> /hi
client.rb logs
127.0.0.1 - - [07/Mar/2013 23:57:46] "GET / HTTP/1.1" 304 - 0.0093
localhost - - [07/Mar/2013:23:57:46 CET] "GET / HTTP/1.1" 304 0
- -> /
I did a lot a search about Cross-origin resource sharing and I tested many different ways. I currently have no idea how to process. Thank you for any help.
Edit:
My problem is that, the api.rb server return an error 404 after the AngularJS call. Moreover, there is two OPTIONS /hi requests, which is weird. I think it's a CORS symptom, but I added some header in order to accept cross-origin queries.
Instead of this, the server should return a 200 with the JSON. I really don't see how to fix it.
I had to add the following to my sinatra app to get it to work with CORS and angular:
options "*" do
response.headers["Allow"] = "HEAD,GET,PUT,DELETE,OPTIONS"
# Needed for AngularJS
response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept"
halt HTTP_STATUS_OK
end
I also used sinatra-cross_origin, but you might not need that seeing as you set the headers manually.

oauth not firing auth/facebook on production

I have built a rails app with both facebook and twitter integration, everything was working fine on development but after moving to production (I have changed the url on fb and twitter settings to my site url subdomain.domain.com) oauth is not triggering only. It is pointing to unicorn corn file name and giving invalid URI error. I have pasted the error below. Any help is highly appreciated...
URI::InvalidURIError (the scheme http does not accept registry part: unicorn_txt_browser (or bad hostname?)):
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/generic.rb:213:in `initialize'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/http.rb:84:in `initialize'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:214:in `new'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:214:in `parse'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/uri/common.rb:747:in `parse'
omniauth (1.1.1) lib/omniauth/strategy.rb:404:in `full_host'
omniauth-oauth2 (1.0.3) lib/omniauth/strategies/oauth2.rb:34:in `callback_url'
omniauth-facebook (1.4.0) lib/omniauth/strategies/facebook.rb:106:in `callback_url'
omniauth-oauth2 (1.0.3) lib/omniauth/strategies/oauth2.rb:46:in `request_phase'
omniauth-facebook (1.4.0) lib/omniauth/strategies/facebook.rb:94:in `request_phase'
omniauth (1.1.1) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.1) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.1) lib/omniauth/builder.rb:48:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.5) lib/action_dispatch/middleware/flash.rb:238:in `call'
I got the issue, in my nginx conf file, the proxy pass was "unicorn_txt_browser" where underscore is not allowed, changing it to "unicorn-txt-browser" fixed the issue....

Facebook Sinatra app doing strange redirects

We have a Facebook application implemented as tabs in a page. However, for certain users, it does weird redirects. This doesn't happen for everyone though, which is why I can't wrap my head around it.
When I go in Chrome incognito mode to our page without being logged in, it seems to happen to me too. What happens exactly?
The multiple tabs on the left of the page are our application tabs. However, something seems to go wrong when clicking on them. I always get the same frontpage, which is the 'Socialabs' page. My heroku logs indicate this:
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "POST /small HTTP/1.1" 302 - 0.0025
2012-02-17T14:29:09+00:00 heroku[router]: POST socialapp.herokuapp.com/small dyno=web.1 queue=0 wait=0ms service=28ms status=302 bytes=0
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "GET / HTTP/1.1" 302 - 0.0009
2012-02-17T14:29:09+00:00 heroku[router]: GET socialapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=10ms status=302 bytes=0
2012-02-17T14:29:09+00:00 app[web.1]: 193.191.150.2 - - [17/Feb/2012 14:29:09] "GET /tab HTTP/1.1" 200 2173 0.0112
2012-02-17T14:29:09+00:00 heroku[router]: GET socialapp.herokuapp.com/tab dyno=web.1 queue=0 wait=0ms service=14ms status=200 bytes=2173
What seems to happen when a user visits, in this case, the 'Small' tab is as follows:
a POST happens to the /small route of our application. This is to be expected. However, instead of rendering our erb template for that route, we get another redirect: /. This route redirects to /tab, as specified in our routes.
I can't figure out why /small redirects to /. The route looks like this in our sinatra application:
get "/contact" do
erb :contact
end
post "/contact" do
#on fb post we redirect to get route and display view
redirect '/contact'
end
I really can't figure this out. The complete contents of my app.rb file can be found in this gist: https://gist.github.com/1864561
Thanks in advance
From your app.rb you have:
before do
# HTTPS redirect
if settings.environment == :production && request.scheme != 'https'
redirect "https://#{request.env['HTTP_HOST']}"
end
end
I don't know the Facebook api or how their apps work, but it looks like it could be this filter that's redirecting any none https request to /.

Problems with deploying GWT with RPC to tomcat (web.xml problem probably)

My gwt app that uses mysql database runs normaly in eclipse when debugging. When i run it on tomcat, it displays correctly but when i click on a button that makes a RPC (executes servlet and contacts the database) i get an error. I checked my tomcat log and i see 404 error when clicking on a button:
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/Bazica.html HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/Bazica.css HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/bazica.nocache.js HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/ F0C186B415ADBD43522C686552368517.cache.html HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/gwt/standard/images/hborder.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:33:29 +0200] "POST /Bazica/war/bazica/greet HTTP/1.1" 404 1024
I guess this is a problem with web.xml file and url-pattern. I guess i don't understand this url-pattern, where should it point to?
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.test.baze.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/bazica/greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Bazica.html</welcome-file>
</welcome-file-list>
</web-app>
My interface has an annotation RemoteServiceRelativePath("greet"), i think it's relevant:
package com.test.baze.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
#RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
}
I tried changing url-pattern to the folder of my service implementation /WEB-INF/classes/com/test/baze/server but my app hangs with no message.
Could you please help me change my web.xml or sth. else to get my app working on a Tomcat. Tnx.
If you take a look at the docs, your URL pattern should be:
<url-pattern>/module_name/greet</url-pattern>
But in your web.xml, you've set the module name to "bazica". Are you renaming the module in your GWT module file (.gwt.xml file) to bazica? If you're not, you'll either have to rename it or use the full path to the GWT module file.