specific - Errores de Ruby On Rails con javascript_include_tag
rails load js on specific page (2)
Así que mi problema, por lo que puedo decir, parece ser que Ruby no está cargando todos sus archivos javascript ya que no estoy recibiendo mensajes de confirmación y link_to con el método:: delete no hace nada por mí.
Con la configuración predeterminada que se me proporciona, los rieles son nuevos
La sección de vistas views / layouts / application.html.erb es la siguiente.
<head>
<title>Myrubyblog</title>
<%= stylesheet_link_tag ''default'', media: ''all'', ''data-turbolinks-track'' => true %>
<%= javascript_include_tag ''default'', ''data-turbolinks-track'' => true%>
<%= csrf_meta_tags %>
</head>
Lo cual me da el error
Started GET "/posts" for 127.0.0.1 at 2015-02-27 02:14:57 -0600
ActiveRecord::SchemaMigration Load (0.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PostsController#index as HTML
Post Load (1.0ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (11.0ms)
Completed 200 OK in 76ms (Views: 54.0ms | ActiveRecord: 4.0ms)
Started GET "/stylesheets/default.css" for 127.0.0.1 at 2015-02-27 02:14:58 -0600
ActionController::RoutingError (No route matches [GET] "/stylesheets/default.css"):
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call''
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app''
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged''
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call''
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call''
rack (1.5.2) lib/rack/runtime.rb:17:in `call''
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call''
rack (1.5.2) lib/rack/lock.rb:17:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call''
rack (1.5.2) lib/rack/sendfile.rb:112:in `call''
railties (4.1.8) lib/rails/engine.rb:514:in `call''
railties (4.1.8) lib/rails/application.rb:144:in `call''
rack (1.5.2) lib/rack/lock.rb:17:in `call''
rack (1.5.2) lib/rack/content_length.rb:14:in `call''
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread''
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
_trace.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_
route.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_
table.html.erb (9.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
routing_error.html.erb within rescues/layout (46.1ms)
Started GET "/javascripts/default.js" for 127.0.0.1 at 2015-02-27 02:14:58 -0600
ActionController::RoutingError (No route matches [GET] "/javascripts/default.js"):
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call''
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app''
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged''
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged''
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call''
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call''
rack (1.5.2) lib/rack/runtime.rb:17:in `call''
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call''
rack (1.5.2) lib/rack/lock.rb:17:in `call''
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call''
rack (1.5.2) lib/rack/sendfile.rb:112:in `call''
railties (4.1.8) lib/rails/engine.rb:514:in `call''
railties (4.1.8) lib/rails/application.rb:144:in `call''
rack (1.5.2) lib/rack/lock.rb:17:in `call''
rack (1.5.2) lib/rack/content_length.rb:14:in `call''
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run''
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread''
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
_trace.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_
route.html.erb (2.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/routes/_
table.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
routing_error.html.erb within rescues/layout (35.8ms)
Este error también ocurre cuando cambio el stylescheet_link_tag y javascript_include_tag para usar: predeterminado en lugar de ''default''.
Este error parece estar ocurriendo porque /javascripts/default.js no existe, así que encontré estos dos artículos que decían que: el valor predeterminado ya no es compatible.
Rails 4 link_to Destruye no funciona en el tutorial de Introducción
Eliminar enlace envía "Obtener" en lugar de "Eliminar" en la vista de Rails 3
Después de cambiar ''predeterminado'' a ''aplicación'', recibí el siguiente error.
La sección de vistas views / layouts / application.html.erb es la siguiente.
<head>
<title>Myrubyblog</title>
<%= stylesheet_link_tag ''application'', media: ''all'', ''data-turbolinks-track'' => true %>
<%= javascript_include_tag ''application'', ''data-turbolinks-track'' => true%>
<%= csrf_meta_tags %>
</head>
Lo cual me da el error
Started GET "/posts" for 127.0.0.1 at 2015-02-27 02:26:28 -0600
ActiveRecord::SchemaMigration Load (1.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PostsController#index as HTML
Post Load (1.0ms) SELECT "posts".* FROM "posts"
Rendered posts/index.html.erb within layouts/application (12.0ms)
Completed 500 Internal Server Error in 2198ms
ActionView::Template::Error (TypeError: Object doesn''t support this property or method
(in c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)):
3: <head>
4: <title>Myrubyblog</title>
5: <%= stylesheet_link_tag ''application'', media: ''all'', ''data-turbolinks-track'' => true %>
6: <%= javascript_include_tag ''application'', ''data-turbolinks-track'' => true %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___474145341_51059580''
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
_trace.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
_request_and_response.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/
template_error.html.erb within rescues/layout (20.0ms)
¿Alguien tiene alguna idea de mi problema?
Mis rutas y gemfile para referencia si es necesario.
routes.rb
Rails.application.routes.draw do
get ''categories/index''
get ''categories/edit''
get ''categories/new''
get ''categories/show''
get ''home/index''
resources :posts
resources :categories
root ''home#index''
end
gemfile
source ''https://rubygems.org''
# Bundle edge Rails instead: gem ''rails'', github: ''rails/rails''
gem ''rails'', ''4.1.8''
# Use sqlite3 as the database for Active Record
#gem ''sqlite3''
gem ''pg''
# Use SCSS for stylesheets
gem ''sass-rails'', ''~> 4.0.3''
# Use Uglifier as compressor for JavaScript assets
gem ''uglifier'', ''>= 1.3.0''
# Use CoffeeScript for .js.coffee assets and views
gem ''coffee-rails'', ''~> 4.0.0''
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem ''therubyracer'', platforms: :ruby
# Use jquery as the JavaScript library
gem ''jquery-rails''
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem ''turbolinks''
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem ''jbuilder'', ''~> 2.0''
# bundle exec rake doc:rails generates the API under doc/api.
gem ''sdoc'', ''~> 0.4.0'', group: :doc
# Use ActiveModel has_secure_password
# gem ''bcrypt'', ''~> 3.1.7''
# Use unicorn as the app server
# gem ''unicorn''
# Use Capistrano for deployment
# gem ''capistrano-rails'', group: :development
# Use debugger
# gem ''debugger'', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem ''tzinfo-data'', platforms: [:mingw, :mswin]
- Cambie sus ''valores predeterminados'' en ambas líneas a ''aplicación''
- Inserta esto en el archivo gema: gem ''coffee-script-source'', ''1.8.0''
- Luego ejecute esto en el símbolo del sistema: bundle update coffee-script-source
Esta respuesta de Figjeti también funcionó para mí. :)
cambie sus ''valores predeterminados'' en ambas líneas a ''aplicación''
inserta esto en el archivo gema:
gem ''coffee-script-source'', ''1.8.0''
luego ejecute esto en el símbolo del sistema:
bundle update coffee-script-source
solucionó mis problemas, espero que solucione los tuyos también :)