小编The*_*Guy的帖子

导轨 | 如何在生产中查看实时服务器日志?

如何像开发中显示的那样查看生产中的实时服务器日志?

服务器登录开发

如果有帮助,我的应用程序在 digitalOcean 上。我使用独角兽作为我的生产服务器。

当我这样做时tail -f log/production.log,我只能看到一些这样的迁移信息,但不能看到实时请求信息以及正在运行的 SQL 查询。

在此处输入图片说明

此外,在我的production.rb,我改变了config.log_level:debug

logging ruby-on-rails production-environment unicorn server

5
推荐指数
1
解决办法
1610
查看次数

优步API | 为Ride请求请求访问令牌会返回'invalid_grant'错误

我希望用户从我的应用程序请求优步游乐设施.
https://developer.uber.com/docs/rides/authentication

在上面的url的OAuth 2.0部分,有6个步骤:
1.授权(完成)
2.接收重定向(完成)
3.获取访问令牌('invalid_grant'错误)

以下截图来自Postman.我尝试将client_id,client_secret,grant_type,redirect_uri和代码作为params,form-data和x-www-form-url-encoded传递.但每次它返回相同的错误.

在此输入图像描述

我在我的优步应用程序控制台中将' http:// localhost:3000/auth/uber/callback '作为重定向网址.

我甚至在终端中尝试了以下curl命令,但它返回相同的'invalid_grant'错误

在此输入图像描述

有人可以帮我解决这个问题.

post curl uber-api

5
推荐指数
1
解决办法
869
查看次数

如何提高 ILIKE 性能?

我的应用程序有一个页面,其中显示了以特定字母开头的州的所有城市。

例如:

State: Alabama, Page A
--> All cities in Alabama starting with alphabet 'A'
Run Code Online (Sandbox Code Playgroud)

这是我的查询

City.where(state: 'Alabama').where("name ilike?", "a%")
Run Code Online (Sandbox Code Playgroud)

此查询需要约 110 - 140 毫秒。有什么方法可以将查询时间降低到 <10 毫秒。

提前致谢 :)

postgresql ruby-on-rails rails-activerecord

1
推荐指数
1
解决办法
765
查看次数

导轨| 拯救模型中的异常并使用控制器中的错误

我正在使用twitter gem 来允许用户从我的应用程序发布推文。

这是我的 tweet.rb 文件

 class Tweet < ActiveRecord::Base
     belongs_to :user

     validates :user_id, :tweet, presence: true
     before_create :post_to_twitter

     def post_to_twitter
       begin
        user.twitter.update(tweet)
       rescue Twitter::Error => error
        // I want to do a redirect_to root_path, notice: "Please fix the error #{error.message}"
       // but its against MVC structure to pattern for a model to redirect, since its the task of a controller. How can I achieve this in controller
       end
     end
    end
Run Code Online (Sandbox Code Playgroud)

在 post_to_twitter 方法的救援块中,我想做一个redirect_to root_path, notice: "Please fix …

twitter ruby-on-rails rescue

1
推荐指数
1
解决办法
8483
查看次数

红宝石 CSV | 阅读CSV时如何跳过几列?

我正在使用Active record Import gem将数据从 CSV 文件批量导入数据库。但我想在导入时跳过几个 CSV 列。

例如,我的 xaa.csv 有名称、作者、author_id、评级等标题。导入时,我想跳过“author_id”列值并导入所有其他列。

books = CSV.read("/public/xaa.csv") //What more should I do here to skip the 3rd column
columns = [:name, :author, :rating]
Book.import columns, books, :validate => false
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails activerecord-import

1
推荐指数
1
解决办法
1824
查看次数