Forum: Ruby on Rails jquery_ujs.js 404

Fba85550f845ee03a40e5397d1164048?d=identicon&s=25 Rodrigo Lueneberg (rodusa)
on 2014-04-26 05:22
I am getting this annoying error which relates to jquery_ujs.js not
being served. Any clues?

This is the site link:
http://test.kopy.com.br/home/index

GET http://test.kopy.com.br/assets/jquery_ujs.js?body=1 404 (Not Found)
index:11
GET http://ads.panoramtech.net/loader.js?client=tac
net::ERR_BLOCKED_BY_CLIENT rev.js:4
Error in event handler for (unknown): Cannot read property 'state' of
null
Stack trace: TypeError: Cannot read property 'state' of null
    at CSRecorder.onQueryStateCompleted
(chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:43:13)
    at messageListener (extensions::messaging:340:9)
    at Function.target.(anonymous function)
(extensions::SafeBuiltins:19:14)
    at EventImpl.dispatchToListener (extensions::event_bindings:395:22)
    at Function.target.(anonymous function)
(extensions::SafeBuiltins:19:14)
    at publicClass.(anonymous function) [as dispatchToListener]
(extensions::utils:69:26)
    at EventImpl.dispatch_ (extensions::event_bindings:378:35)
    at EventImpl.dispatch (extensions::event_bindings:401:17)
    at Function.target.(anonymous function)
(extensions::SafeBuiltins:19:14)
    at publicClass.(anonymous function) [as dispatch]
(extensions::utils:69:26) extensions::event_bindings:383
event.returnValue is deprecated. Please use the standard
event.preventDefault() instead. jquery.js:75

This is my application.rb
// This is a manifest file that'll be compiled into application.js,
which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory,
lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced
here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll
appear at the bottom of the
// compiled file.
//
// Read Sprockets README
(https://github.com/sstephenson/sprockets#sprockets...) for
details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

// **************** this is my production *************************
Kopy2::Application.configure do
  # Settings specified here will take precedence over those in
config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do
this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Generate digests for assets URLs
  config.assets.digest = true

  # Defaults to nil and saved in location specified by
config.assets.prefix
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for
nginx

  # Force all access to the app over SSL, use Strict-Transport-Security,
and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  config.log_level = :debug

  # Prepend all log lines with the following tags
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset
server
  # config.action_controller.asset_host = "http://assets.example.com"

  # Precompile additional assets (application.js, application.css, and
all non-JS/CSS are already added)
  config.assets.precompile += %w[*.js *.css *.png *.jpg *.jpeg *.gif]

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall
back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

  # Log the query plan for queries taking more than this (works
  # with SQLite, MySQL, and PostgreSQL)
  # config.active_record.auto_explain_threshold_in_seconds = 0.5
end

// **************** This is my application.html.erb ***********
<!DOCTYPE html>
<html>
<head>
  <title>Kopy</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
 <%= javascript_include_tag 'application' %>
  <%= csrf_meta_tags %>
</head>
<body>sdfsdsds

<%= yield %>

</body>
</html>

// **************** This is my home.html.erb *********************
<!DOCTYPE html>
<html>
<head>
  <title>Admin Kopy</title>
  <%= csrf_meta_tags %>
  <link href="/assets/home.css?body=1" media="all" rel="stylesheet"
type="text/css">
  <%= stylesheet_link_tag("home") %>
  <script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0...
  <script
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10...
  <script src="/assets/jquery_ujs.js?body=1"
type="text/javascript"></script>
  <script src="/assets/jquery.simplemodal.1.4.4.min.js"
type="text/javascript"></script>
  <script src="/assets/jquery.mask.min.js"
type="text/javascript"></script>
  <script src="/assets/basic.js" type="text/javascript"></script>
  <link href="/assets/simplemodal/basic.css" rel="stylesheet"
type="text/css">
  <!-- IE6 "fix" for the close png image -->
  <!--[if lt IE 7]>
  <link type='text/css' href='css/basic_ie.css' rel='stylesheet'
media='screen' />
  <![endif]-->
</head>
<body>
<div id="Container">
  <div id="Header">
    <div id="TopHeader"> <%= image_tag("logo.png") %> </div>
    <div id="BottomHeader">
      <ul class="sub-menu">
        <li> <%= link_to "Home", :controller => "home", :action =>
"index" %> </li>
        <li> <%= link_to "Bureaus", :controller => "bureaus", :action =>
"index" %> </li>
        <%= RUBY_VERSION%> - <%= Rails.env %>
        <% if !session[:user_id].nil? %>
            <li>
                  <%= link_to "Minha Conta", :controller =>
"my_account", :action => "index" %>
            </li>
        <% end %>
        <li> <%= link_to "Registrar", :controller =>
"user_registration", :action => "new" %> </li>
        <li>
          <% if !session[:user_id].nil? %>
              <%= link_to "Logout", :controller => "access", :action =>
"logout" %>
          <% else %>
              <%= link_to "Login", :controller => "access", :action =>
"login" %>
          <% end %>
        </li>
        <li style="margin-left:25px"> <%= session[:username] %> </li>
      </ul>
    </div>
  </div>
  <div id="ContentWrapper">
    <div id="Content"> <%= yield %> </div>
  </div>
  <div id="Footer"> footer </div>
</div>
</body>
</html>
F50d3b02eee623a2172b58c09fe31c2c?d=identicon&s=25 mike2r (Guest)
on 2014-04-27 22:50
(Received via mailing list)
On Friday, April 25, 2014 11:22:23 PM UTC-4, Ruby-Forum.com User wrote:
> net::ERR_BLOCKED_BY_CLIENT rev.js:4
>     at Function.target.(anonymous function)
> event.preventDefault() instead. jquery.js:75
> //
> //= require jquery_ujs
>
>
>   # Specifies the header that your server uses for sending files
>
> server
>   # config.threadsafe!
>   # with SQLite, MySQL, and PostgreSQL)
>   <%= csrf_meta_tags %>
> <html>
>
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10...
>   <!-- IE6 "fix" for the close png image -->
>       <ul class="sub-menu">
>         <% end %>
>         </li>
> </html>
>
> --
> Posted via http://www.ruby-forum.com/.
>

need to see the controller code.  Basically, it's executing
home.html.erb
as a layout (it's not using the application.html.erb).  Because of this,
the following statement is missed:

<%= javascript_include_tag 'application' %>

I may have a better idea of exactly what's happening when I see the
controller code.  I'm also assuming that you have gem 'jquery-rails' in
your Gemfile.

Also, I would recommend you read the following guide as you aren't
properly
using layouts and templates:

http://edgeguides.rubyonrails.org/layouts_and_rendering.html
Fba85550f845ee03a40e5397d1164048?d=identicon&s=25 Rodrigo Lueneberg (rodusa)
on 2014-04-27 23:12
Thanks for looking at it. There goes the home controller bellow. And yes
I am using gem 'jquery-rails'. What is funny is that in my development
environment locally it is working. This error is from an passenger/nginx
installation.
Rod

class HomeController < ApplicationController
layout 'home'

  def index

    #sleep 1.5
    #@shops = Shop.order("name").page(params[:page])
    @shops = Shop.order('created_at desc').paginate(:per_page => 2,
:page => params[:page])
    #User.paginate(:page => params[:page])

    #query = Product.joins(:category)
    query = Shop.joins(:product_options).where("product_id=1")
    sql = query.to_sql

    sql = "SELECT * from products"
    r = ActiveRecord::Base.connection.execute(sql)
    @query = r = r

    zip= params[:zip]
    @foundZip=false

    if (!zip.nil? && !zip.blank?)
      zip = zip.gsub('.','')
      gc = GeoCity.find_by_ZIP(zip)
    end

    if (!gc.nil? && zip!=nil && !zip.blank?) # found zip
      @foundZip=true
    end

      if request.xhr?
        respond_to do |format|
          format.html
          format.js {render 'index' }
        end
      end
  end
end




mike2r wrote in post #1144230:
> On Friday, April 25, 2014 11:22:23 PM UTC-4, Ruby-Forum.com User wrote:
>> net::ERR_BLOCKED_BY_CLIENT rev.js:4
>>     at Function.target.(anonymous function)
>> event.preventDefault() instead. jquery.js:75
>> //
>> //= require jquery_ujs
>>
>>
>>   # Specifies the header that your server uses for sending files
>>
>> server
>>   # config.threadsafe!
>>   # with SQLite, MySQL, and PostgreSQL)
>>   <%= csrf_meta_tags %>
>> <html>
>>
>
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10...
>>   <!-- IE6 "fix" for the close png image -->
>>       <ul class="sub-menu">
>>         <% end %>
>>         </li>
>> </html>
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>
> need to see the controller code.  Basically, it's executing
> home.html.erb
> as a layout (it's not using the application.html.erb).  Because of this,
> the following statement is missed:
>
> <%= javascript_include_tag 'application' %>
>
> I may have a better idea of exactly what's happening when I see the
> controller code.  I'm also assuming that you have gem 'jquery-rails' in
> your Gemfile.
>
> Also, I would recommend you read the following guide as you aren't
> properly
> using layouts and templates:
>
> http://edgeguides.rubyonrails.org/layouts_and_rendering.html
F50d3b02eee623a2172b58c09fe31c2c?d=identicon&s=25 mike2r (Guest)
on 2014-04-28 17:25
(Received via mailing list)
On Sunday, April 27, 2014 5:12:41 PM UTC-4, Ruby-Forum.com User wrote:
>   def index
>
>     end
>       end
> >> event.preventDefault() instead. jquery.js:75
> >> <html>
> >> --
> > I may have a better idea of exactly what's happening when I see the
> Posted via http://www.ruby-forum.com/.
>

The statement causing the problem is:

layout 'home'

Rails uses layouts and templates in its view rendering system (plus
other
things, but let's start with that).  The default layout is
application.html.erb.  With the above statement, you've overridden the
default.  I'm assuming that you were having issues because the default
template for this action would be index.html.erb and you wanted it to be
home.html.erb.  You would accomplish that by 1) get rid of the layout
statement and 2) insert the following statement at the end of the index
action:

 render template: 'home'

You will have some other issues when you do this.  The layout is
intended
to be the overall framework and, at a minimum, includes the following:
<!DOCTYPE html>
<html>
.
.
</html>

The contents of the template (home.html.erb) will be inserted where you
see
the word yield in the application layout.  In your case, you've defined
the
doctype and html tag in both the application layout and the template
which
will result in the html tag being defined twice which is invalid html.
 Again, I refer you to the guide linked above.

You're going to have a few other issues.  You are separately loading the
jquery and jquery-ui files from google.  Once you have this working
correctly, that will result in those files being loaded twice and
potentially two different versions:  the rails version and the version
you're loading from google.

I also encourage you to go through a good tutorial such as
railstutorial.org.  You seem to have a pretty good foundation in ruby,
so I
don't think it would take you long to go through the tutorial.  You are
doing a lot of things in your controller that 1) you don't need to do if
you work with Rails conventions and 2) some of them belong in a model.
Fba85550f845ee03a40e5397d1164048?d=identicon&s=25 Rodrigo Lueneberg (rodusa)
on 2014-04-29 02:32
Thank you very much, It looks like you're right. All these problems
began to occur after I moved the app to production using
passenger/nginx. I used google version because that was the last
version. I did not know this was being included twice by jquery_ujs.js.
In fact, I was able get rid of some of the error by doing some changes
after your suggestion.

To tell you the truth, the problem is not so much programming but
understanding the concepts of about rails architecture and its modules.
This for me is the hard part. I am still at the beginning of the curve,
but I hope with your suggestion and I will get there.

One more thing:

Do you recommend to testing locally with nginx my rails app? I believe
it will bring the closest scenario to the one I am using i production,
specially if I can debug to better understand the errors.

Rod

mike2r wrote in post #1144331:
> On Sunday, April 27, 2014 5:12:41 PM UTC-4, Ruby-Forum.com User wrote:
>>   def index
>>
>>     end
>>       end
>> >> event.preventDefault() instead. jquery.js:75
>> >> <html>
>> >> --
>> > I may have a better idea of exactly what's happening when I see the
>> Posted via http://www.ruby-forum.com/.
>>
>
> The statement causing the problem is:
>
> layout 'home'
>
> Rails uses layouts and templates in its view rendering system (plus
> other
> things, but let's start with that).  The default layout is
> application.html.erb.  With the above statement, you've overridden the
> default.  I'm assuming that you were having issues because the default
> template for this action would be index.html.erb and you wanted it to be
> home.html.erb.  You would accomplish that by 1) get rid of the layout
> statement and 2) insert the following statement at the end of the index
> action:
>
>  render template: 'home'
>
> You will have some other issues when you do this.  The layout is
> intended
> to be the overall framework and, at a minimum, includes the following:
> <!DOCTYPE html>
> <html>
> .
> .
> </html>
>
> The contents of the template (home.html.erb) will be inserted where you
> see
> the word yield in the application layout.  In your case, you've defined
> the
> doctype and html tag in both the application layout and the template
> which
> will result in the html tag being defined twice which is invalid html.
>  Again, I refer you to the guide linked above.
>
> You're going to have a few other issues.  You are separately loading the
> jquery and jquery-ui files from google.  Once you have this working
> correctly, that will result in those files being loaded twice and
> potentially two different versions:  the rails version and the version
> you're loading from google.
>
> I also encourage you to go through a good tutorial such as
> railstutorial.org.  You seem to have a pretty good foundation in ruby,
> so I
> don't think it would take you long to go through the tutorial.  You are
> doing a lot of things in your controller that 1) you don't need to do if
> you work with Rails conventions and 2) some of them belong in a model.
F50d3b02eee623a2172b58c09fe31c2c?d=identicon&s=25 mike2r (Guest)
on 2014-04-29 17:51
(Received via mailing list)
On Monday, April 28, 2014 8:32:17 PM UTC-4, Ruby-Forum.com User wrote:
> This for me is the hard part. I am still at the beginning of the curve,
> mike2r wrote in post #1144331:
> >>
> > template for this action would be index.html.erb and you wanted it to be
> > <html>
> > will result in the html tag being defined twice which is invalid html.
> > so I
> > don't think it would take you long to go through the tutorial.  You are
> > doing a lot of things in your controller that 1) you don't need to do if
> > you work with Rails conventions and 2) some of them belong in a model.
>
> --
> Posted via http://www.ruby-forum.com/.
>

There's generally three levels of testing in Rails:

1) Unit testing:  this is part of the Rails architecture and doesn't
depend
on a browser.  I use rspec/capybara, others use the standard test unit
supplied with Rails, etc.  This is basically automated testing and does
a
very good job of testing controllers/models to insure the right things
are
happening with respect to information produced (or not produced),
retrieved
and saved correctly, etc.

2) Visual testing which is testing in the browser.  When you're writing
views, for example, it's pretty much necessary to see things in a
browser.
 In this case, I always test in development mode because changes you
make
are automatically reflected on a refresh.  This is accomplished by
having
sprockets and the pipeline live.  In production, everything has to be
pre-compiled and that would significantly slow development time.

3) Once you have developed the piece or application that you are now
ready
to show the client/user, you should test it in the nginx/passenger
production environment (or whatever environment the application will be
running in in production).  As you have seen above, things can happen
and
you should always test this before releasing a piece of your work to be
reviewed.

I should note you can use nginx/passenger and run it in the development
environment.  I sometimes do this, sometimes I just use WEBrick (rails
server).

This is just my opinion, there a lot of different ways to do this but
however you do it, and whatever tools best fit you, it is important that
you test.

The railstutorial.org I referred to in the above posts is free and the
tutorial largely focuses on the rails architecture and models.  It takes
you through the construction of a basic twitter-like site step by step,
explaining the concepts as you go.  I think there's one chapter on basic
ruby you could probably skip.

mike
Fba85550f845ee03a40e5397d1164048?d=identicon&s=25 Rodrigo Lueneberg (rodusa)
on 2014-06-01 03:01
thank you Mike.

Good that you pointed out railstutorial.org. I just checked and Michael
Hartl has updated the Learn Rails by Example to version 4. There is a
free version here to read online:
http://www.railstutorial.org/book/beginning
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.