我试图遵循指南使用向导gem对对象进行部分验证,但我一直得到错误未定义的方法`include?' 对于nil:NilClass,无法理解有什么问题,已经尝试按照一步一步的说明进行操作.
日志中的错误显示.
NoMethodError - undefined method `include?' for nil:NilClass:
app/models/property.rb:22:in `active_or_tenants?'
Run Code Online (Sandbox Code Playgroud)
这是我的步骤控制器.
class Properties::BuildController < ApplicationController
include Wicked::Wizard
steps :tenant, :confirmed
def show
@property = Property.find(params[:property_id])
@tenants = @property.tenants.new(params[:tenant_id])
render_wizard
end
def update
@property = Property.find(params[:property_id])
params[:property][:status] = step.to_s
params[:property][:status] = 'active' if step == steps.last
@property.update_attributes(params[:property])
render_wizard @property
end
def create
@property = current_user.properties.build(params[:property])
logger.info @property.attributes
if @property.save
flash[:success] = "Tenant Added"
redirect_to wizard_path(steps.second, :property_id => @property.id)
else
render 'edit'
end
end
end
Run Code Online (Sandbox Code Playgroud)
Property.rb
class Property < ActiveRecord::Base …
Run Code Online (Sandbox Code Playgroud) 我试图从字典中的响应对象获取值,但我一直遇到这个错误,我认为你__getitem__
更常用于类中的索引是错误的吗?
这是代码:
import json
import requests
from requests.auth import HTTPBasicAuth
url = "http://public.coindaddy.io:4000/api/"
headers = {'content-type': 'application/json'}
auth = HTTPBasicAuth('rpc', '1234')
payload = {
"method": "get_running_info",
"params": {},
"jsonrpc": "2.0",
"id": 0,
}
response = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
print("respone is: ", response['result'])
Run Code Online (Sandbox Code Playgroud) 嗨,当我尝试使用另一个类的实例将新对象转换为字典时__dict__
,我正在尝试使用组合来创建一个新类,它向我展示了<__main__.myobjec object at 0x00000000029CA908>
,__dict__
虽然我听说它与新类有关,但我不确定我是否使用错误,非常感谢任何帮助。
class User:
def __init__(self, name, job=None):
self.name = name
self.job = job
class Customer(User):
_ID = 100
def __init__(self, name, job=None):
self.name = name
self.job = job
class Account:
_ID = 0
def __init__(self, name, job=None):
self.customer = Customer(name , "Customer")
def __getattr__(self, attr):
return getattr(self.customer, attr)
Run Code Online (Sandbox Code Playgroud)
>>> A = Account("Abdi")
>>> A.__dict__
{'customer': <__main__.Customer object at 0x109fdbfc8>}
>>>
Run Code Online (Sandbox Code Playgroud) 我正在遵循协议缓冲区教程,但在编译时不断遇到不同的错误。我的addressbook.proto 文件位于/Users/flexmaster411/protobuffer
protoc -I=/Users/flexmaster411/protobuffer --python_out= /Users/flexmaster411/protobuffer/addressbook.proto /Users/flexmaster411/protobuffer
即使我的原型文件上有语法 =“proto3”,我仍然收到以下错误
[libprotobuf WARNING google/protobuf/compiler/parser.cc:471] No syntax specified for the proto file. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
不确定我是否正确完成了导致此问题的目标文件夹设置,感谢任何帮助
syntax = "proto3";
package tutorial;
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message …
Run Code Online (Sandbox Code Playgroud) 当我尝试使用嵌套属性提交此表单时,我一直收到这个未定义的错误,不知道它来自哪里摔跤已经有一段时间了,我试图让用户在委员会模型中选择一个选项提交他们的选择,我不确定我是否正确连接了我的关联,或者错误是否来自表单.是铁路的菜鸟.提前致谢.
错误已 更新
Properties::BuildController#update
app/controllers/properties/build_controller.rb, line 21
Started PUT "/properties/5/build/council" for 127.0.0.1 at 2013-08-18 08:52:07 +0100
Processing by Properties::BuildController#update as HTML
Parameters: {"utf8"=>"?","authenticity_token"=>"wBWQaxtBioqzGLkhUrstqS+cFD/xvEutXnJ0jWNtSa0=", "council_id"=>"1", "commit"=>"Save changes", "property_id"=>"5", "id"=>"council"}
Property Load (0.2ms) SELECT "properties".* FROM "properties" WHERE "properties"."id" = ? LIMIT 1 [["id", "5"]]
Completed 500 Internal Server Error in 35ms
NoMethodError - undefined method `[]=' for nil:NilClass:
Run Code Online (Sandbox Code Playgroud)
理事会观点
<h1>Select Council</h1>
<%= form_tag url_for(:action => 'update', :controller => 'properties/build'), :method => 'put' do %>
<%= select_tag :council_id, options_from_collection_for_select(Council.all, :id, :name) %> …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在开发模式下发送激活电子邮件,我使用application.yml输入我的smtp凭据不确定我缺少什么但由于某种原因我无法发送激活电子邮件.这里是
application.yml
SMTP_PORT: 587
SMTP_DOMAIN: localhost:3000
SMTP_ADDRESS: smtp.gmail.com
SMTP_USERNAME: myemail@gmail.com
SMTP_PASSWORD: myemailpassword
SMTP_AUTHENTICATION: 'plain'
enable_starttls_auto: true
Run Code Online (Sandbox Code Playgroud)
development.rb
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :file
config.action_mailer.file_settings = { location: 'tmp/mails' }
config.action_mailer.default_url_options = { :host => ENV["URL_HOST"] }
Run Code Online (Sandbox Code Playgroud)
token_mailer.rb
def activation(email, token)
@token_url = edit_activation_url token
mail to: email
end
Run Code Online (Sandbox Code Playgroud) python ×2
actionmailer ×1
c++ ×1
dictionary ×1
email ×1
formwizard ×1
json ×1
json-rpc ×1
protocols ×1
python-3.x ×1
ruby ×1
subclass ×1
validation ×1