我今天开始学习Ruby on rails.我已经安装了Ruby,DEVELOPMENT KIT,SQLite3,bundler和rails.
接下来,我的教科书说要rails new todo
在控制台中运行.然后,出现以下消息:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed (https://rubygems.org/gems/coffee-rails-4.0.1.gem)
An error occurred while installing execjs (2.2.2), and Bundler cannot
continue.
Make sure that `gem install execjs -v '2.2.2'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)
我做了如下.
C:\rubyfolder>gem install execjs -v 2.2.2
Run Code Online (Sandbox Code Playgroud)
然后它出现如下:
Fetching: execjs-2.2.2.gem (100%)
Successfully installed execjs-2.2.2
Parsing documentation for execjs-2.2.2
Installing ri documentation for execjs-2.2.2
Done installing documentation for execjs after 1 seconds
WARNING: Unable to pull data from …
Run Code Online (Sandbox Code Playgroud) 我是Javascript和html的初学者.我想输出10"嗨",但以下代码不起作用.我该怎么办?
index.html和app.js位于同一个文件夹中.
的index.html
<html>
<head>
</head>
<body>
<div class = "test"></div>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
app.js
var main = function(){
for(var i = 0; i<10; i++){
var f = document.createElement('p');
f.innerText = "Hi.";
var div = document.getElementByClass('test');
div.appendChild(f);
};
$(document).ready(main);
Run Code Online (Sandbox Code Playgroud) 我收到了这个错误,我不知道该怎么做.它说
Invalid single-table inheritance type: 1 is not a subclass of Game
Run Code Online (Sandbox Code Playgroud)
它说这个错误发生在games_controller.rb中的9处.
即
@game = current_user.created_games.build(game_params)
Run Code Online (Sandbox Code Playgroud)
我不明白发生了什么以及我应该写什么来指明这个错误的原因.我在这里复制并粘贴game.rb,user.rb,application_controller.rb和games_controller.rb.
game.rb 是
class Game < ActiveRecord::Base
belongs_to :owner, class_name: 'User'
end
Run Code Online (Sandbox Code Playgroud)
user.rb是
class User < ActiveRecord::Base
has_many :created_games, class_name: 'Game', foreign_key: :owner_id
def self.find_or_create_from_auth_hash(auth_hash)
provider = auth_hash[:provider]
uid = auth_hash[:uid]
nickname = auth_hash[:info][:nickname]
image_url = auth_hash[:info][:image]
User.find_or_create_by(provider: provider, uid: uid) do |user|
user.nickname = nickname
user.image_url = image_url
end
end
end
Run Code Online (Sandbox Code Playgroud)
application_controller.rb是 …
在我的ApplicationController中,有current_use
.
private
def current_user
return unless session[:user_id]
@current_user ||= User.find(session[:user_id])
end
def logged_in?
!!session[:user_id]
end
Run Code Online (Sandbox Code Playgroud)
logged_in?
并验证工作.但是,当我改变
<% if logged_in? %>
Run Code Online (Sandbox Code Playgroud)
至
<% if logged_in? && current_user.free? %>
Run Code Online (Sandbox Code Playgroud)
在views/top/index.html.erb中,发生以下错误.
NameError at /
undefined local variable or method `current_user' for #<#<Class:...>:...>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
free?
在user.rb中定义为
def free?
visit.game.count == 0
end
Run Code Online (Sandbox Code Playgroud)
添加
如果我current_user
改为@current_user
,错误信息变为如下.
NoMethodError at /
undefined method `free?' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)