熟悉ROR并使用示例页面,但当我转到localhost时正遇到以下错误:3000
无法在以下路径中找到带有“application/javascript”类型的“action_cable”文件:<...>
我不知道是什么导致了这个/如何修复,但是如果我在我的控制器文件中添加“布局错误”,那么一切都正常。以下是档案:
这是我的创业板文件:
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查看文件:
<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>模型文件:
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控制器文件:
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*请注意,如果取消注释“布局错误”行,所有的工作,但我没有布局。
发布于 2016-11-13 23:02:36
简短答覆:
只要删除/app/ cable.js /javascripts/中的,就可以解决这个问题。
较长的答覆:
为了确保你不会再次出现这个问题,这里有一些回顾性的推测。
我的猜测是,您已经在您的系统中安装了RoR 5.x,并且在生成您认为是4.x RoR应用程序之后,使用
#rails _4.x.x_ new app_name你最终得到了一个5.x的RoR应用程序。现在,即使手动更新Gemfile表示需要rails 4.x.x,您的项目仍然会有一些剩余文件,其中一个是cable.js文件。这就是我认为你看到的错误。
现在,如何避免这种情况。据我所知,以上强制执行旧rails版本的方法是没有文档的,而且并不总是有效的。这是另一种肯定有效的方法。
假设您全局安装了一个5.x RoR,并且希望对一个名为rails4_app的项目强制执行RoR v.4.x.x,那么:
#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现在,您已经启动了rails 4.x.x应用程序。
发布于 2016-08-31 18:31:08
ActionCable是Rails 5的一个特性,但是您在Gemfile中指定了Rails 4
https://stackoverflow.com/questions/39256557
复制相似问题