Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeChat 命令行模式在Rails 6命令行模式下,报 NameError: uninitialized constant Rails 错 #268

Closed
emtfe opened this issue Sep 1, 2019 · 7 comments
Assignees

Comments

@emtfe
Copy link

emtfe commented Sep 1, 2019

如题,您的gem非常好,但由于微信会不断增加新功能,接口调试也需要日志支持
使用您的gem的用户,有可能不只盯着某些最新的版本,也许要支持老版本,这些都需要日志。
类似:
autoload :Logging, ...

module Wechat
class << self
attr_writer :logger

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = self.name
  end
end

end
end

再次感谢

@Eric-Guo
Copy link
Owner

Eric-Guo commented Sep 1, 2019

直接使用rails的logger不行吗?

Rails.logger.debug "想输出啥就是啥"

@emtfe
Copy link
Author

emtfe commented Sep 1, 2019

感谢回复。
我直接调用您的命令行,是没有Rails的logger可用的
另外 为啥直接console调用 wechat 可用显示调用方法
但我调用 wechat callbackip
提示错误
。。 t-0.11.5/bin/wechat:34:in callbackip': undefined method callbackip' for true:TrueClass (NoMethodError)
我漏掉了上面么?

@Eric-Guo
Copy link
Owner

Eric-Guo commented Sep 1, 2019

要不你还是暂时用rails c把,好像新的Rails 6在这块,wechat有一个bug....

[deployer@thape-web current]$ bundle exec rails c
Loading production environment (Rails 6.0.0)
irb(main):001:0> Wechat.api.callbackip
=> {"ip_list"=>["223.166.222.100", "223.166.222.101", "223.166.222.102", "223.166.222.103", "223.166.222.104", "223.166.222.105", "223.166.222.106", "223.166.222.107", "223.166.222.111", "223.166.222.112", "223.166.222.117", "223.166.222.118", "101.91.60.80", "101.91.60.81", "121.51.66.16", "121.51.66.19", "121.51.66.26", "121.51.66.120", "157.255.192.54", "157.255.192.55", "58.60.9.75", "58.60.9.76", "58.60.9.77", "58.60.9.78", "59.36.121.222", "59.36.121.223", "121.51.162.73", "121.51.162.74", "121.51.162.55", "103.7.30.71", "103.7.30.70", "103.7.30.69", "103.7.30.68", "203.205.219.187", "203.205.219.188", "203.205.219.189", "203.205.219.190"]}

@Eric-Guo Eric-Guo changed the title 需要加一个logger 的支持 WeChat 命令行模式在Rails 6命令行模式下,报 NameError: uninitialized constant Rails 错 Sep 1, 2019
@Eric-Guo Eric-Guo self-assigned this Sep 1, 2019
@emtfe
Copy link
Author

emtfe commented Sep 1, 2019

嗯 好
加一个ruby 内部日志,也很方便
直接上面

module Wechat
autoload :Message, 'wechat/message'
autoload :Responder, 'wechat/responder'
autoload :Cipher, 'wechat/cipher'
autoload :ControllerApi, 'wechat/controller_api'

class << self
attr_writer :logger

def logger
  @logger ||= Logger.new($stdout).tap do |log|
    log.progname = self.name
  end
end

end
....

就能调用了
Wechat.logger.info "Wechat Concern Common"

@Eric-Guo
Copy link
Owner

Eric-Guo commented Sep 2, 2019

大概的原因我知道了,因为wechat.yml中写了Rails.application.credentials.wechat_secret!的话,由于wechat跑的时候,没有loading Rails的这个方法,所以无法运行。

Eric-Guo added a commit that referenced this issue Sep 2, 2019
Eric-Guo added a commit that referenced this issue Sep 2, 2019
@Eric-Guo
Copy link
Owner

Eric-Guo commented Sep 2, 2019

好像比较难修,先报个错,或者使用figaro

@Eric-Guo
Copy link
Owner

最新版本已经修了,v0.15.0。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants