Two Chainz
Two Chainz

Reputation: 1

Sprockets::FileNotFound at / couldn't find file 'action_cable' with type 'application/javascript'

New to ROR and working through a sample page but am experiencing the following error when I go to localhost:3000

couldn't find file 'action_cable' with type 'application/javascript' Checked in these paths: <...>

I'm not sure what is causing this/how to fix but if I add "layout false" to my controller file then everything works ok. Below are the files:

Here is my gem file:

source 'https://rubygems.org'
ruby '2.3.0'
gem 'rails', '4.2.4'

# Rails defaults
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'byebug'
gem 'web-console'
gem 'spring'
gem 'foundation-rails', '~> 5.5'
gem 'gibbon'
gem 'high_voltage'
gem 'simple_form'
group :development do
  gem 'better_errors'
  gem 'quiet_assets'
  gem 'rails_layout'
end
gem 'sqlite3'
group :production do
  gem 'pg'
  gem 'rails_12factor'
end

View file:

 <h1>Home</h1>
 <p>Welcome to the home of <%= @owner.name %>. </p>
 <p>I was born on <%= @owner.birthdate %>
 <p>Only <%= @owner.countdown %> days until my birthday!</p>

Model File:

class Owner
    def name
            name = 'Foobar Radigan'
    end

        def birthdate
            birthdate = Date.new(1990,12,22)
        end

        def countdown
                today = Date.today
                birthday = Date.new(today.year, birthdate.month, birthdate.day)
                if birthday > today
                        countdown = (birthday - today).to_i
                else
                        countdown = (birthday.next_year - today).to_i
                end
        end

end

Controller file:

 class VisitorsController < ApplicationController
        # Do not use layout
        # layout false

    def new
            Rails.logger.debug 'DEBUG: entering new method'
            @owner = Owner.new
            render 'visitors/new'
            Rails.logger.debug 'DEBUG: owner name is ' + @owner.name
    end

end

*Note that if uncomment the 'layout false' line everything works, but I have no layout.

Upvotes: 0

Views: 3683

Answers (2)

Anton Nikiforov
Anton Nikiforov

Reputation: 3485

SHORT ANSWER:

Just delete cable.js in /app/assets/javascripts/ and that should fix the problem.

LONG ANSWER:

To make sure you don't have this problem reappearing, here's a bit of retrospective speculation.

My guess is that you have RoR 5.x installed in your system globally, and after you generated what you thought was a 4.x RoR app using

#rails _4.x.x_ new app_name

you ended up having a 5.x RoR app instead. Now, even if you manually update Gemfile indicating that you need rails 4.x.x, your project will still have some leftovers, one of which being a cable.js file. That's how I think you got the error you see.

Now, how to avoid this. From what I understand, the above method of enforcing the older rails version is undocumented and not always works. Here's another method that surely works.

Suppose you have a 5.x RoR installed globally and want to enforce RoR v.4.x.x for a project called rails4_app, then:

#mkdir rails4_app
#cd rails4_app
#echo "source 'https://rubygems.org'" > Gemfile
#echo "gem 'rails', '3.2.17'" >> Gemfile
#bundle install
#bundle exec rails new . --force --skip-bundle
#bundle update

And here you go - now you have your rails 4.x.x app bootstrapped.

Upvotes: 4

shlajin
shlajin

Reputation: 1576

ActionCable is a feature of Rails 5, but you specified Rails 4 in your Gemfile

Upvotes: 0

Related Questions