我在一个我必须写的大功能里面.在最后一部分中,我必须计算数据框中列的平均值.我操作的列的名称是作为函数的参数给出的.
我正在阅读Michael Hartl撰写的Ruby on Rails教程并继续阅读.我在尝试做一些测试时遇到了问题.
[fran@fran-desktop twitter-clone]$ bundle exec rake test
/media/Data.II/Dropbox/Web Development/odin-project/3. Ruby on Rails/twitter-clone/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /media/Data.II/Dropbox/Web Development/odin-project/3. Ruby on Rails/twitter-clone/config/application.rb to limit the frameworks that will be loaded.
/home/fran/.gem/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- guard (LoadError)
from /home/fran/.gem/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /home/fran/.gem/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /home/fran/.gem/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /usr/lib/ruby/gems/2.2.0/gems/guard-minitest-2.4.4/lib/minitest/guard_minitest_plugin.rb:4:in `<top (required)>'
from /home/fran/.gem/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require' …Run Code Online (Sandbox Code Playgroud) 我正在按照教程学习API的基础知识,但我遇到了麻烦.这就是我所做的:
Rails.application.routes.draw do
namespace :api, constraints: {format: :json} do
resources :kittens
end
end
#app/controllers/api/kittens_controller.rb
class API::KittenController < ApplicationController
def index
end
end
#config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
end
Run Code Online (Sandbox Code Playgroud)
访问/ api/kittens时出错
Unable to autoload constant API::KittensController, expected /media/Volume.II/Dropbox/Web Development/odin-project/3. Ruby on Rails/odin-kittens/app/controllers/api/kittens_controller.rb to define it
Extracted source (around line #495):
else
require_or_load(expanded, qualified_name)
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
return from_mod.const_get(const_name)
end
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.谢谢.
我遇到的问题是byebug类在第一个之后被忽略了.这很奇怪.我启动服务器.每当有一个byebug声明时,如果它是自服务器启动以来的第一个声明,它就会起作用.如果没有,它会说这个消息:*** Byebug already started. Ignoringbyebug call.和调试器工作的唯一方法是重启服务器(它只能工作一次).
任何帮助将非常感激.
顺便说一句,这发生在每个项目中.
谢谢.
尝试使用sqlalchemy连接到postgres数据库时,我遇到此身份验证问题.这就是我的联系方式:
db_url = 'postgresql+psycopg2:///<role>:<pass>@localhost:5432/basketball'
Engine = create_engine(db_url, echo=False)
SessionMaker = ORM.sessionmaker(bind=Engine, autoflush=False)
Session = ORM.scoped_session(SessionMaker)
Run Code Online (Sandbox Code Playgroud)
这就是我的设置方式 /etc/postgresql/9.3/main/pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Run Code Online (Sandbox Code Playgroud)
然后,当访问db我得到:
SQLAlchemy (psycopg2.OperationalError) fe_sendauth: no password supplied
Run Code Online (Sandbox Code Playgroud) class Match(Base):
__tablename__ = 'matches'
id = Column(Integer, primary_key=True)
date = Column(Date, nullable=False)
time = Column(Time, nullable=True)
league_id = Column(ForeignKey('leagues.id'), nullable=False, index=True)
league = relationship('League', backref='matches')
type = Column(enums.matches_types)
home_team_id = Column(ForeignKey('teams.id'), nullable=False, index=True)
home_team = relationship('Team', foreign_keys=[home_team_id], backref='home_matches')
away_team_id = Column(ForeignKey('teams.id'), nullable=False, index=True)
class Team(Base):
__tablename__ = 'teams'
id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
country_id = Column(ForeignKey('countries.id'), nullable=False, index=True)
country = relationship('Country', backref='teams')
Run Code Online (Sandbox Code Playgroud)
我需要编写一个连接列和团队表的查询,显示本地和远程团队的团队信息.
Session.query(Match.date, Match.home_team.name, Match_away_team.name).joins(Team)
Run Code Online (Sandbox Code Playgroud)
这回来了 Can't determine join between 'matches' and 'teams'; tables have …
模型 FacebookPost 和 TwitterPost 共享一个名为 types 的枚举。在创建 facebook_posts 表时正确创建了此枚举,但是在尝试创建 twitter_posts 表时,尝试重新创建此类型会导致错误。
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "types" already exists
[SQL: "CREATE TYPE types AS ENUM ('Video', 'GIF', 'Scratch Reel', 'Card', 'Video Card', 'Text', 'Photo', 'Shared Article', 'Reply', 'Canvas', 'Carousel', 'Video Carousel', 'Link', 'Status')"]
Run Code Online (Sandbox Code Playgroud)
这就是我创建数据库的方式。我不能使用 Base.metadata.create_all,因为我需要明确创建哪些表
Engine = create_engine(db_url, echo=False)
Campaign.__table__.create(Engine)
SubCampaign.__table__.create(Engine)
Creative.__table__.create(Engine)
Hashtag.__table__.create(Engine)
FacebookPost.__table__.create(Engine)
TwitterPost.__table__.create(Engine)
Run Code Online (Sandbox Code Playgroud)
我正在以这种方式创建枚举:
from sqlalchemy import Enum
types = ('Video', 'GIF', 'Scratch Reel', 'Card', 'Video Card',
'Text', 'Photo', 'Shared Article', 'Reply', 'Canvas',
'Carousel', 'Video Carousel', 'Link', 'Status')
goals = …Run Code Online (Sandbox Code Playgroud) 我正在玩图形并编写一个mixin模块来创建图形.我想在其中有一些替代构造函数.这就是我所拥有的:
class Graph(GraphDegree, GraphDegreePlot, GraphGeneration, object):
def __init__(self):
self.nodes = set([])
self.edges = {}
def get_nodes(self):
"""
get nodes in graph
"""
return self.nodes
def get_number_of_nodes(self):
"""
get number of nodes in the graph
"""
return len(self.nodes)
def get_edges(self):
"""
get edges in graph
"""
return self.edges
def get_heads_in_edges(self):
"""
get heads in edges present on the graph
"""
return self.edges.values()
def add_node(self, node):
"""
add new node to graph
"""
if node in self.get_nodes():
raise ValueError('Duplicate Node')
else:
self.nodes.add(node) …Run Code Online (Sandbox Code Playgroud) 我在使用 FactoryGirl 时遇到问题,我使用序列来避免重复字段,但无论如何验证都失败了。
输出:
1) CustomersController anonymous user GET #edit is redirected to signin when accessing edit form
Failure/Error: get :edit, id: create(:customer)
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken, Email has already been taken
# ./spec/controllers/customers_controller_spec.rb:25:in `block (4 levels) in <top (required)>'
# -e:1:in `<main>'
3) Customer public class methods executes its methods correctly #find_by_id_or_name finds customer by name
Failure/Error: let(:john) {create(:customer, name: 'John Doe X')}
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken, Email has already been …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python中的ftplib上传文件.
ftp = FTP('...')
ftp.login('user', 'pass')
f = open(filename)
ftp.storbinary(filename, f)
f.close()
ftp.quit()
Run Code Online (Sandbox Code Playgroud)
storbinary正在返回error_perm: 500 Unknown command.,这很奇怪,因为我遵循其规范.Google搜索返回的信息非常少.有谁遇到过这个问题?
python ×5
sqlalchemy ×3
postgresql ×2
ruby ×2
api ×1
byebug ×1
constructor ×1
database ×1
debugging ×1
enums ×1
factory-bot ×1
ftplib ×1
join ×1
mean ×1
minitest ×1
object ×1
oop ×1
r ×1
rake ×1
rspec ×1
sql ×1
validation ×1