rails / coffee-rails

CoffeeScript adapter for the Rails asset pipeline. Also adds support for .coffee views.
MIT License
230 stars 64 forks source link

html format being rendered on a js request #83

Closed NicosKaralis closed 7 years ago

NicosKaralis commented 7 years ago

Steps to reproduce

  1. Create a new rails 5 project. rails new bug
  2. Generate a controller for sessions. rails generate controller sessions new
  3. Confirm that there are 2 views for Sessions#new. new.html.erb, new.coffee
  4. Generate a controller for a protected page. rails generate controller home index
  5. Add a redirect to home#index redirect_to 'sessions/new'
  6. run development server rails s
  7. Opening http://localhost:3000/home/index redirects to sessions#new using html template
  8. Opening http://localhost:3000/home/index.js redirects to sessions#new using html template
  9. Rename new.coffee for the sessions view to new.js.erb. mv app/views/sessions/new.coffee app/views/sessions/new.js.erb
  10. Opening http://localhost:3000/home/index redirects to sessions#new using html template
  11. Opening http://localhost:3000/home/index.js redirects to sessions#new using js template

Expected behavior

If the file app/views/sessions/new.coffee is present opening http://localhost:3000/home/index.js should redirect to sessions#new and use the js compiled from the coffee template.

Actual behavior

Tell us what happens instead

The html template is rendered instead the coffee template

This is the log output:

If the file app/views/sessions/new.coffee is present

Started GET "/home/index" for 127.0.0.1 at 2016-11-18 09:57:19 -0200
Processing by HomeController#index as JS
Redirected to http://localhost:3000/sessions/new

Started GET "/login" for 127.0.0.1 at 2016-11-18 09:57:20 -0200
Processing by SessionController#new as JS
  Rendering admin/session/new.html.erb
  Rendered admin/session/new.html.erb (5.2ms)
Completed 200 OK in 42ms (Views: 34.4ms | ActiveRecord: 0.0ms)

If the file app/views/sessions/new.js.erb is present

Started GET "/home/index" for 127.0.0.1 at 2016-11-18 09:41:34 -0200
Processing by HomeController#index as JS
Redirected to http://localhost:3000/sessions/new

Started GET "/login" for 127.0.0.1 at 2016-11-18 09:41:35 -0200
Processing by SessionController#new as JS
  Rendering admin/session/new.js.erb
  Rendered admin/session/new.js.erb (3659.3ms)
Completed 200 OK in 3846ms (Views: 3835.5ms | ActiveRecord: 0.0ms)

If the file app/views/sessions/new.coffee is present and the file app/views/sessions/new.html.erb is not present

Started GET "/home/index" for 127.0.0.1 at 2016-11-18 09:58:45 -0200
Processing by HomeController#index as JS
Redirected to http://localhost:3000/sessions/new

Started GET "/login" for 127.0.0.1 at 2016-11-18 09:58:45 -0200
Processing by SessionController#new as JS
  Rendering admin/session/new.coffee
  Rendered admin/session/new.coffee (636.9ms)
Completed 200 OK in 668ms (Views: 659.3ms | ActiveRecord: 0.0ms)

System configuration

Rails version: Rails 5.0.0.1

Ruby version: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]

Gem list:

*** LOCAL GEMS ***

actioncable (5.0.0.1)
actionmailer (5.0.0.1)
actionpack (5.0.0.1)
actionview (5.0.0.1)
activejob (5.0.0.1)
activemodel (5.0.0.1)
activerecord (5.0.0.1)
activesupport (5.0.0.1)
arel (7.1.4)
bcrypt (3.1.11)
bigdecimal (1.2.8)
builder (3.2.2)
bullet (5.4.2)
bundler (1.13.6)
bundler-unload (1.0.2)
byebug (9.0.6)
coffee-rails (4.2.1)
coffee-script (2.4.1)
coffee-script-source (1.10.0)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
did_you_mean (1.0.0)
erubis (2.7.0)
execjs (2.7.0)
executable-hooks (1.3.2)
ffi (1.9.14)
gem-wrappers (1.2.7)
globalid (0.3.7)
i18n (0.7.0)
io-console (0.4.5)
jbuilder (2.6.0)
jquery-rails (4.2.1)
json (1.8.3)
kgio (2.10.0)
listen (3.0.8)
loofah (2.0.3)
mail (2.6.4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (3.2016.0521)
mina (1.0.3)
mina-npm (1.0.0.beta2)
mini_portile2 (2.1.0)
minitest (5.9.1, 5.8.3)
multi_json (1.12.1)
net-telnet (0.1.1)
newrelic_rpm (3.17.1.326)
nio4r (1.2.1)
nokogiri (1.6.8.1)
open4 (1.3.4)
pg (0.19.0)
power_assert (0.2.6)
psych (2.0.17)
puma (3.6.0)
rack (2.0.1)
rack-test (0.6.3)
rails (5.0.0.1)
rails-dom-testing (2.0.1)
rails-html-sanitizer (1.0.3)
railties (5.0.0.1)
raindrops (0.17.0)
rake (11.3.0, 10.4.2)
rb-fsevent (0.9.8)
rb-inotify (0.9.7)
rdoc (4.2.1)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
sass (3.4.22)
sass-rails (5.0.6)
spring (2.0.0)
spring-watcher-listen (2.0.1)
sprockets (3.7.0)
sprockets-rails (3.2.0)
sqlite3 (1.3.12)
test-unit (3.1.5)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
turbolinks (5.0.1)
turbolinks-source (5.0.0)
tzinfo (1.2.2)
uglifier (3.0.3)
unicorn (5.2.0)
uniform_notifier (1.10.0)
web-console (3.4.0)
websocket-driver (0.6.4)
websocket-extensions (0.1.2)

Additional Information

On my development machine, because I have a new.html with actual content this is the output when I open /login.js

Started GET "/login.js" for 127.0.0.1 at 2016-11-18 10:12:18 -0200
Processing by Admin::SessionController#new as JS
  Parameters: {"subdomain"=>"admin"}
  Rendering admin/session/new.html.erb
  Rendered admin/session/new.html.erb (6.1ms)
Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.
Completed 422 Unprocessable Entity in 44ms (Views: 22.9ms | ActiveRecord: 0.0ms)

ActionController::InvalidCrossOriginRequest (Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.):

actionpack (5.0.0.1) lib/action_controller/metal/request_forgery_protection.rb:239:in `verify_same_origin_request'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:382:in `block in make_lambda'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:218:in `block in halting'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:456:in `block in call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:456:in `each'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:456:in `call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (5.0.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (5.0.0.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (5.0.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (5.0.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
activerecord (5.0.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (5.0.0.1) lib/abstract_controller/base.rb:126:in `process'
actionview (5.0.0.1) lib/action_view/rendering.rb:30:in `process'
actionpack (5.0.0.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (5.0.0.1) lib/action_controller/metal.rb:262:in `dispatch'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
actionpack (5.0.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
bullet (5.4.2) lib/bullet/rack.rb:10:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/etag.rb:25:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/head.rb:12:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
activerecord (5.0.0.1) lib/active_record/migration.rb:552:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
newrelic_rpm (3.17.1.326) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (2.0.1) lib/rack/handler/webrick.rb:86:in `service'
/Users/nicoskaralis/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/Users/nicoskaralis/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/Users/nicoskaralis/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
  Rendering /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
  Rendering /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (14.9ms)
  Rendering /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.7ms)
  Rendering /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (11.5ms)
  Rendered /Users/nicoskaralis/.rvm/gems/ruby-2.3.1@connect-ads-channel-server/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (110.8ms)

Originally opened on rails/rails#27095

pixeltrix commented 7 years ago

Closing because this doesn't appear to be a bug.