小编Joh*_*ohn的帖子

Rails 中的 Active Record 和 ORM 有什么区别?

Actice Record 和 ORM 之间有什么区别吗?一些文件说两者是一样的。真的吗?

ruby orm activerecord ruby-on-rails

8
推荐指数
2
解决办法
4733
查看次数

如何在两个日期时间字段的rails中获得几分钟的时差?

我想计算两个date_time字段之间的时间差(以分钟为单位).像created_at和updated_at种类的字段.我想要这样的结果updated_at - created_at = some minutes.

这些时间出现在印度的时区.我怎么能在铁轨上做到这一点?

created = article.created_at
updated = article.updated_at

minutes = updated - created
Run Code Online (Sandbox Code Playgroud)

time ruby-on-rails difference

6
推荐指数
2
解决办法
9270
查看次数

heroku版本在ubuntu 14.04中执行命令"heroku version"时给出错误"ERROR:EOF"?

我使用以下命令在我的ubuntu 14.04操作系统中安装了heroku toolbelt.

wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
Run Code Online (Sandbox Code Playgroud)

它已安装在我的系统中.之后,当我键入heroku版本时,我收到错误.

prashant@prashant-pc:~$ heroku version
ERROR: EOF
!    error getting commands pid 18296 exit 1
prashant@prashant-pc:~$ heroku login
ERROR: EOF
!    error getting commands pid 18440 exit 1
prashant@prashant-pc:~$ 
Run Code Online (Sandbox Code Playgroud)

谁可以帮我这个事?

这是我执行安装命令时的终端输出,

wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh

prashant@prashant-pc:~$ wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
--2015-12-12 15:35:45--  https://toolbelt.heroku.com/install-ubuntu.sh
Resolving toolbelt.heroku.com (toolbelt.heroku.com)... 75.101.151.245, 107.20.142.220, 184.72.95.196
Connecting to toolbelt.heroku.com (toolbelt.heroku.com)|75.101.151.245|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 719 [text/plain]
Saving to: ‘STDOUT’

100%[=====================================================================================================>] 719         --.-K/s   in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku-toolbelt ubuntu-14.04

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

尝试从Ruby程序连接到MS Access数据库时出现错误:“在'require'中:无法加载此类文件-win32ole(LoadError)“

通过我在Ubuntu下运行的Ruby程序,我试图连接到另一台运行Windows的计算机上的Access数据库。我收到错误

'要求':无法加载此类文件-Win32ole(LoadError)

我面临的另一个问题是系统上不存在Access文件,因此在这里我要使用文件所在的系统中的ip addressand port numberuser nameand password,以便通过Internet连接可以连接并获取数据。不幸的是,我不知道在下面的代码中可以在哪里指定这些详细信息。

connect_to_access_db.rb

require 'win32ole'

connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.ACE.OLEDB.12.0;
             Data Source=c:\path\filename.accdb')


SQLstatement = "SELECT * FROM TABLE"
recordset = WIN32OLE.new('ADODB.Recordset')
res = recordset.Open(SQLstatement, connection)
p res
Run Code Online (Sandbox Code Playgroud)

如何建立与Access数据库的连接?

ruby windows ubuntu ms-access dbconnection

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

无法打开与localhost:9200的TCP连接(连接被拒绝-“ localhost”端口9200的connect(2))(Faraday :: ConnectionFailed)

我收到错误消息:Puma捕获了此错误:无法在ubuntu 14.04的rails应用程序中打开与localhost:9200的TCP连接(拒绝连接-“ localhost”端口9200的connect(2))(Faraday :: ConnectionFailed)。

以下是我在终端中进行弹性搜索的输出:

prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch restart
 * Starting Elasticsearch Server                                                                                                               prashanth@prashanth-OptiPlex-390:~$ sudo service elasticsearch start
 * Starting Elasticsearch Server                                                                                                                * Already running.                                                                                                                     [ OK ] 
prashanth@prashanth-OptiPlex-390:~$ curl -X GET 'http://localhost:9200'
curl: (7) Failed to connect to localhost port 9200: Connection refused
prashanth@prashanth-OptiPlex-390:~$ 
Run Code Online (Sandbox Code Playgroud)

这是/etc/elasticsearch/elasticsearch.yml文件中我的弹性搜索设置

network.host: 127.0.0.1
transport.tcp.port: 9200
http.port: 9200
Run Code Online (Sandbox Code Playgroud)

错误说明:

Puma caught this error: Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200) (Faraday::ConnectionFailed)
/home/prashanth/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/net/http.rb:882:in `rescue in …
Run Code Online (Sandbox Code Playgroud)

tcp ruby-on-rails elasticsearch ubuntu-14.04

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

引导日期时间选择器,12小时时钟不显示轨道中的子午线(上午或下午)?

我想以这种方式显示date_time格式,11/01/2013 12:00 AM但目前它显示11/01/2013 12:00 P如下.子午线指示器"P"始终显示"P"而不是显示上午或下午.

我正在关注我的rails应用程序的这个链接bootstrap日期时间选择器.

$('#datetimepicker1').datetimepicker({
             format : 'DD/MM/YYYY hh:mm P'   
        });
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails datetime-format twitter-bootstrap-3

3
推荐指数
1
解决办法
2万
查看次数

wickedpdf无法在Rails的本地和亚马逊AWS中渲染图像?

我正在使用wickedpdfgem pdf invoicehtml代码生成。

宝石:

gem 'wicked_pdf'
gem "wkhtmltopdf-binary"
Run Code Online (Sandbox Code Playgroud)

gemfile.lock

wicked_pdf (1.0.6)
wkhtmltopdf-binary (0.9.9.3)
Run Code Online (Sandbox Code Playgroud)

在控制器中:

  def show_pdf_invoice
    respond_to do |format|
      format.html { render :layout => "pdf.pdf.erb" }
      format.pdf do
    render pdf: "show_pdf_invoice", :layout => 'pdf.pdf.erb'
    #render :pdf => "pdf"#, :layout => 'pdf.html.erb'
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

views/invoices/show_pdf_invoice.pdf.erb

  <img id="image" src="https://www.google.co.in/logos/doodles/2016/holidays-2016-day-2-6356741311692800-scta.png" alt="logo" /> 
  <%= wicked_pdf_image_tag 'https://www.google.co.in/logos/doodles/2016/holidays-2016-day-2-6356741311692800-scta.png' %>
Run Code Online (Sandbox Code Playgroud)

pdf正在生成。但是图像没有显示。在图片的位置出现了空盒子。找不到问题。

ruby-on-rails image amazon-web-services wicked-pdf

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

如何为rails中的新表单设置文本字段的默认值?iam使用:value =>"0".但在编辑形式中我也获得'0'值

如何仅为rails中的新表单设置文本字段的默认值?我正在使用:value => "0"形式偏.但问题是虽然我在数据库中有一个值,但我在编辑形式中得到0.实际上在文本字段的新形式中我默认分配0,当用户没有选择任何值时.但是当用户更改该值并保存表单时,同时在显示编辑表单时,我得到"0"值.当编辑表单中的数据库中有值时,如何避免显示"0"?这是我正在使用的语法.

   <%= f.text_field :duration , :size=>"4", :value => "0" %>
Run Code Online (Sandbox Code Playgroud)

forms default ruby-on-rails textfield

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

如何设计和自定义 rails 日期时间选择字段?

我在我的表中有一个日期时间字段,在用户视图中选择我使用 datetime_select 视图助手的日期时间。我想用引导程序类来设置它的样式,我不想要它显示的默认日期格式。如何格式化此日期时间选择以及如何设置此字段的样式?

这是我现在使用的代码。

 <%= f.datetime_select :check_out_req , ampm: true , :class => "form-control"%>
Run Code Online (Sandbox Code Playgroud)

它以格式显示日期时间选择下拉列表year,month, date,hours, minutes。但我希望它以格式显示下拉列表day,month,year,hours,minutes

当我应用这样:class => "form-control"的样式时,样式不是 applyig。如何设计这个领域?

css format datetime ruby-on-rails twitter-bootstrap

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

尝试在 rails 中使用 Gmail API 进行身份验证时,没有路由匹配 [GET] "/auth/google_oauth2" 错误

尝试使用 Rails 中的 Gmail API 进行身份验证时,出现 No route matching [GET] "/auth/google_oauth2" 错误。

按照这篇文章https://www.twilio.com/blog/2014/09/gmail-api-oauth-rails.html,我正在实现 Gmail API 集成。

代码似乎是正确的。但不知道是什么问题。

在路由文件中:

  root to: 'visitors#index'
  if defined?(Devise)
    devise_for :users, :controllers => { :registrations => "registrations", :passwords => "passwords", omniauth_callbacks: 'omniauth_callbacks' }
    devise_scope :user do
      get 'auth/:provider/callback', :to => 'users/omniauth_callbacks#facebook'
    end
  end
  get "/auth/:provider/callback" => "candidates#authenticate_from_google"
Run Code Online (Sandbox Code Playgroud)

在 rake 路线中,我什至也有路线。

GET /auth/:provider/callback(.:format)  candidates#authenticate_from_google

  
Run Code Online (Sandbox Code Playgroud)

在 Gemfile 中:-

gem "omniauth"
gem "omniauth-linkedin"
gem "jwt", "~> 1.4.1"
gem "linkedin-scraper", "~> 0.1.5"
gem "omniauth-facebook"
gem "omniauth-google-oauth2"
gem 'signet' …
Run Code Online (Sandbox Code Playgroud)

routes ruby-on-rails omniauth gmail-api

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