Home php c# sql c c++ javascript python java go android git linux asp.net django .net node.js ios xcode cocoa iphone mysql tomcat mongodb bash objective-c scala visual-studio apache elasticsearch jar eclipse jquery ruby-on-rails ruby rubygems android-studio spring lua sqlite emacs ubuntu perl docker swift amazon-web-services svn html ajax xml java-ee maven intellij-idea rvm macos unix css ipad postgresql css3 json windows-server vue.js typescript oracle hibernate internet-explorer github tensorflow laravel symfony redis html5 google-app-engine nginx firefox sqlalchemy lucene erlang flask vim solr webview facebook zend-framework virtualenv nosql ide twitter safari flutter bundle phonegap centos Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 31

0
votes
answers
8 views
+10

如何查找工作流中是否觸發了事件?

0

我們在Rails應用中使用Geekq/workflow。這裏有一個例子:如何查找工作流中是否觸發了事件?

class Article 
    include Workflow 
    workflow do 
    state :new do 
     event :submit, :transitions_to => :awaiting_review 
    end 
    state :awaiting_review do 
     event :review, :transitions_to => :being_reviewed 
    end 
    state :being_reviewed do 
     event :accept, :transitions_to => :accepted 
     event :reject, :transitions_to => :rejected 
    end 
    state :accepted 
    state :rejected 
    end 
end 

這是很容易找到,如果一個狀態,例如,:awaiting_review已經經歷了:

article.current_state < :awaiting_review 

然而,我們沒有發現檢查的方法事件已被解僱。正在檢查一個事件是否被工作流的內置方法激發了一些可能的東西?或者如果沒有這個工作流程,其他任何可以?

+0

什麼操作你想要在事件發生時執行?在轉換到另一個狀態之前,您可以使用'before_transition'來執行操作。希望這會有所幫助。 –

+0

只需檢查一個事件是否爲一個實例觸發。沒有對事件進行操作。 – user938363

+0

然後你可以使用before_transition。每當發生任何事件時,都會調用轉換,並在轉換之前記錄它。 –

沙发
0
0

所以,你可以捕捉on_create的事件和on_update,因爲存在於它的回調在ActiveRecord的,但在工作流程change_state,你需要重寫工作流程的轉變,由:

class Article < BaseModel 

include Workflow 
    workflow do 
    state :new do 
     event :submit, :transitions_to => :awaiting_review 
    end 
    state :awaiting_review do 
     event :review, :transitions_to => :being_reviewed 
    end 
    state :being_reviewed do 
     event :accept, :transitions_to => :accepted 
     event :reject, :transitions_to => :rejected 
    end 
    state :accepted 
    state :rejected 

    on_transition do |from, to, event, *event_args| 
     self.update_attribute(:status, to) 
     # this triggers on_update callback on workflow transition 
     # which you can use to log the event now 
    end 
    end 
end 

class BaseModel < ActiveRecord 
    after_commit :log_create_event, on: [:create] 
    after_commit :log_update_event, on: [:update] 
    after_commit :log_destroy_event, on: [:destroy] 

    def log_create_event 
    #log_event('Create') 
    end 

    def log_update_event 
    #log_event('Update') 
    end 

    def log_destroy_event 
    #log_event('Destroy') 
    end 
end 
0
votes
answers
8 views
+10

如何在Xcode中構建項目Ruby?

5

我有一個關於Mac上的Ruby的問題。當我bulid項目,有一個錯誤如下:如何在Xcode中構建項目Ruby?

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- plist (LoadError) 

from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require' 
    from .../app.build/Debug-iphonesimulator/iphone.build/Script-2095E433129114D900424894.sh:3 
Command /bin/sh failed with exit code 1 

的Xcode 4.3.3安裝在我的電腦,它使用的是Mac OS X 10.7.4上,我安裝了Ruby 1.9.3與RVM並設置作爲默認的紅寶石1.9.3:

$ rvm use 1.9.3 

Using ../.rvm/gems/ruby-1.9.3-p194 

$ ruby -v 

ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] 

有人知道解決方案來解決這個問題嗎?

+1

嗨,我有完全相同的問題。我遵循這個教程:http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/,它的工作。 – 2012-07-12 09:51:49

+1

非常感謝你,這意味着我應該卸載Xcode,RMVM,紅寶石,並重新安裝它們? – user1520033 2012-07-12 15:03:14

+0

這就是我所要做的。等待其他答案,也許還有另一種解決方案。 – 2012-07-12 15:12:20

沙发
0
0

您可能需要在Xcode中安裝命令行工具?我認爲你打開Xcode,進入首選項並在那裏,你可以安裝命令行工具。之後你可能需要重新編譯你的rvm ruby??。

0
votes
answers
8 views
+10

替代rails集成測試的控制器測試應該始終堅持db?

0

我正在發現與測試流相關的Rails集成測試,並且我有一些關於使用集成測試替換控制器測試(在rails 5中不推薦使用)的行業標準的問題。替代rails集成測試的控制器測試應該始終堅持db?

通常我們有微小的控制器,我們可以獲取參數,調用正確的協作者並準備響應,並且很容易通過直接在控制器對象上嘲諷協作者來測試它。

我很擔心將每個控制器測試遷移到集成測試的開銷,而持久化db。這種情況的標準是什麼?

只測試一條路線/動作而不是完整流程時的標準是什麼?

我們怎麼能代替這個?:

@controller.stubs(:authenticate).returns(true) 
沙发
0
0

集成測試旨在模仿真實用戶。他們打算全面測試整個應用程序。

意見因此而異。對我而言,這意味着你應該完全避免嘲弄/嘲笑。沒有一件事情被嘲諷或嘲笑,一切都完全執行。這意味着我編寫的每個集成測試都要通過輸入用戶名和密碼的實際身份驗證過程。有些步驟是多餘的,是的。

集成測試比單元/控制器測試更慢。切斷驗證步驟可能不會爲您節省足夠的時間從長遠來看有所作爲(無雙關語意圖)。

+0

感謝您的回答!同意一切。在將控制器測試遷移到集成測試時(如Rails 5中所建議的),身份驗證和存儲用戶不會產生差異,但將每個模型存儲在db中會帶來很多開銷。你做了一個軌道集成測試,爲每個控制器動作存儲所有的數據庫? – Jorge

+0

@Jorge我使用燈具/工廠來創建我所需要的當前測試。 –

0
votes
answers
8 views
+10

不同的時間和服務器的時區

0

我的服務器的時區設置爲IST。我所有的工作都會延遲5小時30分鐘(偏離格林威治標準時間)。我按照這個線程https://github.com/javan/whenever/pull/239並嘗試所有相關的補丁,但他們都沒有爲我工作。每當選擇工作時,哪個時區會起作用?不同的時間和服務器的時區

+0

你可以做,在這種方式 '需要File.expand_path( '../配置/環境',__dir __)' '每天:一天:在=> Time.zone.parse(09:30AM ')do rake「leave_reminder:daily」 end'或像這樣'每天:,at => '09:30am',by_timezone:'東部時間(美國和加拿大)' rake「leave_reminder:每日「 結束' – Vishal

+0

@Vishal我已經試過了。它似乎沒有幫助。我也嘗試過其他變體,但它們都不適合我 –

沙发
0
0

我想你的網絡服務器/導軌服務器是不同於系統TZ(在命令行中運行date時的那個)。

您可能想要將兩個時區設置爲相同的值。

有關更多信息,請參見https://www.cyberciti.biz/faq/linux-unix-set-tz-environment-variable/

0
votes
answers
7 views
+10

爲什麼我的單元測試試圖插入一個記錄,當我不問它?

0

我正在使用rails 5和devise。我正在爲我的控制器編寫一些單元測試,但我正在跑到一堵牆上。以下是我正在試圖測試爲什麼我的單元測試試圖插入一個記錄,當我不問它?

# GET /issues/new 
    def new 
    unless user_signed_in? 
     redirect_to new_user_session_path 
    end 
    @issue = Issue.new(stop_onestop_id: params[:stop_id], line_onestop_id: params[:line_id]) 
    end 

這裏的方法就是我寫

# issues_controller_test.rb 
class IssuesControllerTest < ActionDispatch::IntegrationTest 

    include Devise::Test::IntegrationHelpers 

    test "logged in should get issues page" do 
    sign_in users(:one) 
    test_stop_id = 1 
    test_line_id = 1 
    get new_issue_url, params: {stop_id: test_stop_id, line_id: test_line_id} 
    assert_equal test_stop_id, @issue.stop.id 
    assert_equal test_line_id, @issue.line.id 
    assert_response :success 
    end 
end 

然而測試,當我運行它,我得到以下例外...

localhost:Caravan-App davea$ rails test 
Running via Spring preloader in process 9509 
Run options: --seed 48437 

# Running: 

E 

Error: 
IssuesControllerTest#test_logged_in_should_get_issues_page: 
ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2017-12-27 19:07:16.234345', '2017-12-27 19:07:16.234345', 298486374) 



bin/rails test test/controllers/issues_controller_test.rb:6 



Finished in 0.320746s, 3.1177 runs/s, 0.0000 assertions/s. 

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips 

沒有我要求創建新記錄的位置,爲什麼我的測試試圖插入一個?

+1

'用戶(:一個)'抓住測試夾具。你有沒有檢查你的'users.yml'夾具文件?你可能會有一些裝置違反了獨特的電子郵件限制。 –

+0

嘗試將'redirect_to new_user_session_path'更改爲'redirect_to new_user_session_path並返回' –

+0

@DerekHopper,使用taht fixture文件進行良好調用。這確實是問題。 – Dave

沙发
0
1

在行sign_in users(:one),users(:one)正在取夾具。看到這告訴我你正在使用一個燈具文件。

您的項目中有一個文件users.yml,它定義了一些用戶進行測試。它看起來像ActiveRecord::RecordNotUnique異常來自那裏。更具體地說,用戶固定裝置似乎違反了對users.email的唯一性約束。

如果您通過爲每個用戶提供一個唯一的電子郵件地址來修復您的users.yml文件,那麼您應該很好。

0
votes
answers
7 views
+10

如何解決「::的ActionView ::模板錯誤(無效字節序列UTF-8):」

1

專家,如何解決「::的ActionView ::模板錯誤(無效字節序列UTF-8):」

我下面一本書的例子建立在回報率我的第一個博客系統。我的操作系統是Win10,Ruby是2.4.2p198,Rails是5.1.4。激活Rails服務器後,我連接到本地主機:3000 /用戶。然後,我會遇到下面的錯誤:

引發ArgumentError中的用戶#指數 顯示C:/Users/joeychou/hello_rails/app/views/layouts/application.html.erb其中線#7提出:

無效的字節序列在UTF-8

而且它強調如下錯誤行:

在軌道上的服務器,該錯誤消息如下:

ActionView::Template::Error (invalid byte sequence in UTF-8): 4: HelloRails 5: <%= csrf_meta_tags %> 6: 7: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 8: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 9: 10:

app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___655117387_94495480'

請告知如何解決此問題,以便我可以繼續前進。任何幫助深表感謝!

Regards,Joey

沙发
0
0

我找到了答案!

coffee-script source> = 1.9.0在Windows下無法正常工作。你可以這樣做:gem'coffee-script-source','1.8.0',強制1.8.0,然後發佈包更新coffee-script-source

請參考下面的鏈接瞭解詳情。 Rails ExecJS::ProgramError in Pages#home?

0
votes
answers
7 views
+10

Rails 5 ActionView :: Template ::錯誤發生在控制器中#action:「嵌套事務」

5

我最近從4遷移到最新的5.1 rails(以及從thin到puma服務器)。我有一個不可重複的錯誤,我無法追蹤它的來源。下面是一個示例應用程序回溯:Rails 5 ActionView :: Template ::錯誤發生在控制器中#action:「嵌套事務」

app/views/reports/_transaction_dialog.html.erb:88:in `_app_views_report= 
s__transaction_dialog_html_erb___259516699_72100400' 
    app/views/reports/show.html.erb:40:in `block in _app_views_reports_show= 
_html_erb___439575899_73388840' 
    app/views/reports/show.html.erb:38:in `_app_views_reports_show_html_erb= 
___439575899_73388840' 
    app/controllers/application_controller.rb:52:in `block in select_shard'= 

    app/controllers/application_controller.rb:48:in `select_shard' 

我知道它不會說太多...它只是一個局部渲染。它發生在代碼的各個地方,但通常在應用程序使用鰭狀肢來檢查功能可用性的地方。這裏_transaction_dialog.html.erb:88有:

 <% if $flipper[:schooling].enabled? current_user %> 

我會嘗試將其報告給flipper但也許有人有其他的想法?我使用章魚進行數據庫分片。下面Gemfile.lock的:

GIT 
    remote: https://github.com/zquestz/omniauth-google-oauth2 
    revision: 605f483311a1885d87fa636791faba109ff37221 
    branch: master 
    specs: 
    omniauth-google-oauth2 (0.5.2) 
     jwt (~> 1.5) 
     omniauth (>= 1.1.1) 
     omniauth-oauth2 (>= 1.3.1) 

GEM 
    remote: https://rubygems.org/ 
    remote: https://rails-assets.org/ 
    specs: 
    actioncable (5.1.4) 
     actionpack (= 5.1.4) 
     nio4r (~> 2.0) 
     websocket-driver (~> 0.6.1) 
    actionmailer (5.1.4) 
     actionpack (= 5.1.4) 
     actionview (= 5.1.4) 
     activejob (= 5.1.4) 
     mail (~> 2.5, >= 2.5.4) 
     rails-dom-testing (~> 2.0) 
    actionpack (5.1.4) 
     actionview (= 5.1.4) 
     activesupport (= 5.1.4) 
     rack (~> 2.0) 
     rack-test (>= 0.6.3) 
     rails-dom-testing (~> 2.0) 
     rails-html-sanitizer (~> 1.0, >= 1.0.2) 
    actionview (5.1.4) 
     activesupport (= 5.1.4) 
     builder (~> 3.1) 
     erubi (~> 1.4) 
     rails-dom-testing (~> 2.0) 
     rails-html-sanitizer (~> 1.0, >= 1.0.3) 
    activejob (5.1.4) 
     activesupport (= 5.1.4) 
     globalid (>= 0.3.6) 
    activemodel (5.1.4) 
     activesupport (= 5.1.4) 
    activerecord (5.1.4) 
     activemodel (= 5.1.4) 
     activesupport (= 5.1.4) 
     arel (~> 8.0) 
    activerecord-sqlserver-adapter (5.1.2) 
     activerecord (~> 5.1.0) 
     tiny_tds 
    activesupport (5.1.4) 
     concurrent-ruby (~> 1.0, >= 1.0.2) 
     i18n (~> 0.7) 
     minitest (~> 5.1) 
     tzinfo (~> 1.1) 
    addressable (2.5.2) 
     public_suffix (>= 2.0.2, < 4.0) 
    ar-octopus (0.9.1) 
     activerecord (>= 4.0.0) 
     activesupport (>= 4.0.0) 
    arel (8.0.0) 
    autoprefixer-rails (7.1.6) 
     execjs 
    axlsx (1.3.6) 
     htmlentities (~> 4.3.1) 
     nokogiri (>= 1.4.1) 
     rubyzip (>= 0.9.5) 
    bcrypt (3.1.11-x64-mingw32) 
    bcrypt (3.1.11-x86-mingw32) 
    bootstrap-sass (3.3.7) 
     autoprefixer-rails (>= 5.2.1) 
     sass (>= 3.3.4) 
    bootstrap_form (2.7.0) 
    builder (3.2.3) 
    byebug (9.1.0) 
    cmxl (0.2.0) 
     rchardet19 
    cocoon (1.2.11) 
    coffee-rails (4.2.2) 
     coffee-script (>= 2.2.0) 
     railties (>= 4.0.0) 
    coffee-script (2.4.1) 
     coffee-script-source 
     execjs 
    coffee-script-source (1.12.2) 
    concurrent-ruby (1.0.5) 
    crass (1.0.3) 
    declarative (0.0.10) 
    declarative-option (0.1.0) 
    devise (4.3.0) 
     bcrypt (~> 3.0) 
     orm_adapter (~> 0.1) 
     railties (>= 4.1.0, < 5.2) 
     responders 
     warden (~> 1.2.3) 
    devise_ldap_authenticatable (0.8.5) 
     devise (>= 3.4.1) 
     net-ldap (>= 0.6.0, <= 0.11) 
    docx (0.2.07) 
     nokogiri (~> 1.5) 
     rubyzip (~> 1.1.6) 
    erubi (1.7.0) 
    erubis (2.7.0) 
    exception_notification (4.2.2) 
     actionmailer (>= 4.0, < 6) 
     activesupport (>= 4.0, < 6) 
    execjs (2.7.0) 
    faraday (0.12.2) 
     multipart-post (>= 1.2, < 3) 
    ffi (1.9.18-x64-mingw32) 
    ffi (1.9.18-x86-mingw32) 
    flipper (0.11.0) 
    flipper-ui (0.11.0) 
     erubis (~> 2.7.0) 
     flipper (~> 0.11.0) 
     rack (>= 1.4, < 3) 
     rack-protection (>= 1.5.3, < 2.1.0) 
    globalid (0.4.1) 
     activesupport (>= 4.2.0) 
    gmail (0.6.0) 
     gmail_xoauth (>= 0.3.0) 
     mail (>= 2.2.1) 
    gmail_xoauth (0.4.2) 
     oauth (>= 0.3.6) 
    google-api-client (0.17.3) 
     addressable (~> 2.5, >= 2.5.1) 
     googleauth (>= 0.5, < 0.7.0) 
     httpclient (>= 2.8.1, < 3.0) 
     mime-types (~> 3.0) 
     representable (~> 3.0) 
     retriable (>= 2.0, < 4.0) 
    googleauth (0.6.2) 
     faraday (~> 0.12) 
     jwt (>= 1.4, < 3.0) 
     logging (~> 2.0) 
     memoist (~> 0.12) 
     multi_json (~> 1.11) 
     os (~> 0.9) 
     signet (~> 0.7) 
    googlecharts (1.6.12) 
    hashie (3.5.6) 
    htmlentities (4.3.4) 
    httpclient (2.8.3) 
    i18n (0.9.1) 
     concurrent-ruby (~> 1.0) 
    jwt (1.5.6) 
    little-plugger (1.1.4) 
    logging (2.2.2) 
     little-plugger (~> 1.1) 
     multi_json (~> 1.10) 
    loofah (2.1.1) 
     crass (~> 1.0.2) 
     nokogiri (>= 1.5.9) 
    mail (2.7.0) 
     mini_mime (>= 0.1.1) 
    memoist (0.16.0) 
    method_source (0.9.0) 
    mime-types (3.1) 
     mime-types-data (~> 3.2015) 
    mime-types-data (3.2016.0521) 
    mini_mime (1.0.0) 
    mini_portile2 (2.3.0) 
    minitest (5.10.3) 
    money (6.10.0) 
     i18n (>= 0.6.4, < 1.0) 
    multi_json (1.12.2) 
    multi_logger (0.1.0) 
     railties 
    multi_xml (0.6.0) 
    multipart-post (2.0.0) 
    net-ldap (0.11) 
    nio4r (2.1.0) 
    nokogiri (1.8.1-x64-mingw32) 
     mini_portile2 (~> 2.3.0) 
    nokogiri (1.8.1-x86-mingw32) 
     mini_portile2 (~> 2.3.0) 
    oauth (0.5.3) 
    oauth2 (1.4.0) 
     faraday (>= 0.8, < 0.13) 
     jwt (~> 1.0) 
     multi_json (~> 1.3) 
     multi_xml (~> 0.5) 
     rack (>= 1.2, < 3) 
    omniauth (1.7.1) 
     hashie (>= 3.4.6, < 3.6.0) 
     rack (>= 1.6.2, < 3) 
    omniauth-oauth2 (1.4.0) 
     oauth2 (~> 1.0) 
     omniauth (~> 1.2) 
    orm_adapter (0.5.0) 
    os (0.9.6) 
    public_suffix (3.0.1) 
    puma (3.11.0) 
    rack (2.0.3) 
    rack-protection (2.0.0) 
     rack 
    rack-test (0.8.2) 
     rack (>= 1.0, < 3) 
    rails (5.1.4) 
     actioncable (= 5.1.4) 
     actionmailer (= 5.1.4) 
     actionpack (= 5.1.4) 
     actionview (= 5.1.4) 
     activejob (= 5.1.4) 
     activemodel (= 5.1.4) 
     activerecord (= 5.1.4) 
     activesupport (= 5.1.4) 
     bundler (>= 1.3.0) 
     railties (= 5.1.4) 
     sprockets-rails (>= 2.0.0) 
    rails-assets-fullcalendar (3.7.0) 
     rails-assets-jquery (>= 2, < 4) 
     rails-assets-moment (>= 2.9.0, < 3) 
    rails-assets-fullcalendar-scheduler (1.9.0) 
     rails-assets-fullcalendar (~> 3.7.0) 
     rails-assets-jquery (>= 2, < 4) 
     rails-assets-moment (>= 2.9.0, < 3) 
    rails-assets-jquery (3.2.1) 
    rails-assets-jquery-ui (1.12.1) 
     rails-assets-jquery (>= 1.6) 
    rails-assets-jquery-ujs (1.2.2) 
     rails-assets-jquery (> 1.8) 
    rails-assets-jqueryui-timepicker-addon (1.6.3) 
    rails-assets-js-cookie (2.2.0) 
    rails-assets-lightbox (2.10.0) 
     rails-assets-jquery (> 2) 
    rails-assets-moment (2.19.3) 
    rails-dom-testing (2.0.3) 
     activesupport (>= 4.2.0) 
     nokogiri (>= 1.6) 
    rails-html-sanitizer (1.0.3) 
     loofah (~> 2.0) 
    railties (5.1.4) 
     actionpack (= 5.1.4) 
     activesupport (= 5.1.4) 
     method_source 
     rake (>= 0.8.7) 
     thor (>= 0.18.1, < 2.0) 
    rake (12.3.0) 
    rb-fsevent (0.10.2) 
    rb-inotify (0.9.10) 
     ffi (>= 0.5.0, < 2) 
    rchardet19 (1.3.7) 
    representable (3.0.4) 
     declarative (< 0.1.0) 
     declarative-option (< 0.2.0) 
     uber (< 0.2.0) 
    responders (2.4.0) 
     actionpack (>= 4.2.0, < 5.3) 
     railties (>= 4.2.0, < 5.3) 
    retriable (3.1.1) 
    ruby-oci8 (2.2.5-x64-mingw32) 
    ruby-oci8 (2.2.5-x86-mingw32) 
    rubyzip (1.1.7) 
    sass (3.5.3) 
     sass-listen (~> 4.0.0) 
    sass-listen (4.0.0) 
     rb-fsevent (~> 0.9, >= 0.9.4) 
     rb-inotify (~> 0.9, >= 0.9.7) 
    sass-rails (5.0.7) 
     railties (>= 4.0.0, < 6) 
     sass (~> 3.1) 
     sprockets (>= 2.8, < 4.0) 
     sprockets-rails (>= 2.0, < 4.0) 
     tilt (>= 1.1, < 3) 
    signet (0.8.1) 
     addressable (~> 2.3) 
     faraday (~> 0.9) 
     jwt (>= 1.5, < 3.0) 
     multi_json (~> 1.10) 
    sprockets (3.7.1) 
     concurrent-ruby (~> 1.0) 
     rack (> 1, < 3) 
    sprockets-rails (3.2.1) 
     actionpack (>= 4.0) 
     activesupport (>= 4.0) 
     sprockets (>= 3.0.0) 
    sqlite3 (1.3.13-x64-mingw32) 
    sqlite3 (1.3.13-x86-mingw32) 
    thor (0.20.0) 
    thread_safe (0.3.6) 
    tilt (2.0.8) 
    tiny_tds (2.1.0-x64-mingw32) 
    tiny_tds (2.1.0-x86-mingw32) 
    tzinfo (1.2.4) 
     thread_safe (~> 0.1) 
    tzinfo-data (1.2017.3) 
     tzinfo (>= 1.0.0) 
    uber (0.1.0) 
    uglifier (3.2.0) 
     execjs (>= 0.3.0, < 3) 
    warden (1.2.7) 
     rack (>= 1.0) 
    websocket-driver (0.6.5) 
     websocket-extensions (>= 0.1.0) 
    websocket-extensions (0.1.3) 
    zip (2.0.2) 

PLATFORMS 
    x64-mingw32 
    x86-mingw32 

DEPENDENCIES 
    activerecord-sqlserver-adapter 
    ar-octopus 
    axlsx 
    bootstrap-sass 
    bootstrap_form 
    byebug 
    cmxl 
    cocoon 
    coffee-rails 
    devise 
    devise_ldap_authenticatable 
    docx 
    exception_notification 
    flipper 
    flipper-ui 
    gmail 
    google-api-client 
    googleauth 
    googlecharts 
    money 
    multi_logger 
    omniauth-google-oauth2! 
    puma 
    rails 
    rails-assets-fullcalendar! 
    rails-assets-fullcalendar-scheduler! 
    rails-assets-jquery! 
    rails-assets-jquery-ui! 
    rails-assets-jquery-ujs! 
    rails-assets-jqueryui-timepicker-addon! 
    rails-assets-js-cookie! 
    rails-assets-lightbox! 
    ruby-oci8 
    sass-rails 
    sqlite3 
    tiny_tds 
    tzinfo-data 
    uglifier 
    zip 

BUNDLED WITH 
    1.16.0 

這是我看到nginx的日誌:

10.86.12.240 - - [27/Dec/2017:13:44:12 +0000] "GET/HTTP/2.0" 200 5589 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" 
10.86.12.240 - - [27/Dec/2017:13:44:18 +0000] "GET /reports/3576 HTTP/2.0" 499 0 "https://quick.roche.com/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" 
10.86.12.240 - - [27/Dec/2017:13:44:19 +0000] "GET /reports/3576 HTTP/2.0" 200 7802 "https://quick.roche.com/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" 

成功(HTTP狀態= 200),初始頁面請求,那麼499和200之後

499是什麼讓我錯誤的鐵軌堆棧

這是我在軌道日誌爲最後兩個請求:

I, [2017-12-27T13:44:18.744420 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Started GET "/reports/3576" for 127.0.0.1 at 2017-12-27 13:44:18 +0000 
I, [2017-12-27T13:44:18.744420 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Processing by ReportsController#show as HTML 
I, [2017-12-27T13:44:18.744420 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Parameters: {"id"=>"3576"} 
D, [2017-12-27T13:44:18.744420 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] [1m[32m[Shard: ir][0m [1m[36mUser Load (0.0ms)[0m [1m[35mEXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[login] = @0 ORDER BY name ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 varchar(8), @1 int', @0 = 'sh', @1 = 1[0m [["login", nil], ["LIMIT", nil]] 
D, [2017-12-27T13:44:18.744420 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (0.0ms)[0m [1m[35mEXEC Delegators @ToolName = N'WebT&E', @user = N'sh', @permission = N'% REPORT'[0m 
I, [2017-12-27T13:44:18.869223 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Started GET "/reports/3576" for 127.0.0.1 at 2017-12-27 13:44:18 +0000 
I, [2017-12-27T13:44:18.869223 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Processing by ReportsController#show as HTML 
I, [2017-12-27T13:44:18.869223 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Parameters: {"id"=>"3576"} 
D, [2017-12-27T13:44:18.869223 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mUser Load (0.0ms)[0m [1m[35mEXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[login] = @0 ORDER BY name ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 varchar(8), @1 int', @0 = 'sh', @1 = 1[0m [["login", nil], ["LIMIT", nil]] 
D, [2017-12-27T13:44:18.869223 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (0.0ms)[0m [1m[35mEXEC Delegators @ToolName = N'WebT&E', @user = N'sh', @permission = N'% REPORT'[0m 
D, [2017-12-27T13:44:19.212432 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (343.2ms)[0m [1m[35mEXEC GetParameters @ToolName = N'WebT&E', @user = N'sh', @user_direct = N'sh', @report_id = N'3576'[0m 
D, [2017-12-27T13:44:19.212432 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (468.0ms)[0m [1m[35mEXEC GetParameters @ToolName = N'WebT&E', @user = N'sh', @user_direct = N'sh', @report_id = N'3576'[0m 
D, [2017-12-27T13:44:19.212432 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mUser Load (0.0ms)[0m [1m[35mEXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[login] = @0 ORDER BY name ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 varchar(8), @1 int', @0 = 'mp', @1 = 1[0m [["login", nil], ["LIMIT", nil]] 
I, [2017-12-27T13:44:19.212432 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendering reports/show.html.erb within layouts/application 
D, [2017-12-27T13:44:19.212432 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] [1m[32m[Shard: ir][0m [1m[36mUser Load (0.0ms)[0m [1m[35mEXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[login] = @0 ORDER BY name ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 varchar(8), @1 int', @0 = 'mp', @1 = 1[0m [["login", nil], ["LIMIT", nil]] 
I, [2017-12-27T13:44:19.212432 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendering reports/show.html.erb within layouts/application 
D, [2017-12-27T13:44:19.228033 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mComment Load (15.6ms)[0m [1m[34mSELECT [comments].* FROM [comments] WHERE (entity='Report' AND entity_id=N'3576')[0m 
D, [2017-12-27T13:44:19.228033 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] [1m[32m[Shard: ir][0m [1m[36mComment Load (15.6ms)[0m [1m[34mSELECT [comments].* FROM [comments] WHERE (entity='Report' AND entity_id=N'3576')[0m 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered reports/_transactions.html.erb (15.6ms) 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_transactions.html.erb (15.6ms) 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered reports/_summary.html.erb (31.2ms) 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_summary.html.erb (31.2ms) 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered reports/show.html.erb within layouts/application (31.2ms) 
I, [2017-12-27T13:44:19.243633 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Completed 500 Internal Server Error in 499ms (ActiveRecord: 483.6ms) 
I, [2017-12-27T13:44:19.259233 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendering F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb 
I, [2017-12-27T13:44:19.274834 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_request.text.erb (0.0ms) 
D, [2017-12-27T13:44:19.274834 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (31.2ms)[0m [1m[35mEXEC account_groups @user = N'mp'[0m 
I, [2017-12-27T13:44:19.290434 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.290434 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_session.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.290434 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.306035 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_environment.text.erb (0.0ms) 
D, [2017-12-27T13:44:19.306035 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (15.6ms)[0m [1m[35mEXEC accounts_for @user = N'mp', @group = N'Travel'[0m 
I, [2017-12-27T13:44:19.306035 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.306035 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_backtrace.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.306035 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.0ms) 
I, [2017-12-27T13:44:19.306035 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Rendered F:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/exception_notification-4.2.2/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb (46.8ms) 
D, [2017-12-27T13:44:19.306035 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (0.0ms)[0m [1m[35mEXEC accounts_for @user = N'mp', @group = N'Congress'[0m 
D, [2017-12-27T13:44:19.306035 #1760] DEBUG -- : [1226f679-086e-4699-a6de-cab43006d58d] #exception_notification: processed outbound mail in 62.4ms 
D, [2017-12-27T13:44:19.321635 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (15.6ms)[0m [1m[35mEXEC accounts_for @user = N'mp', @group = N'Other'[0m 
D, [2017-12-27T13:44:19.399637 #1760] DEBUG -- : [9817073b-8d80-4516-ba8d-040e223d1502] [1m[32m[Shard: ir][0m [1m[36mExecute Procedure (78.0ms)[0m [1m[35mEXEC UnreportedRequests @ToolName = N'WebT&E', @user = N'mp', @ReportId = 3576[0m 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_transaction_dialog.html.erb (156.0ms) 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_split_dialog.html.erb (0.0ms) 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_travel_dialog.html.erb (0.0ms) 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/_additionals_dialog.html.erb (0.0ms) 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Rendered reports/show.html.erb within layouts/application (187.2ms) 
I, [2017-12-27T13:44:19.399637 #1760] INFO -- : [9817073b-8d80-4516-ba8d-040e223d1502] Completed 200 OK in 530ms (Views: 36.4ms | ActiveRecord: 499.2ms) 
I, [2017-12-27T13:44:19.477639 #1760] INFO -- : [1226f679-086e-4699-a6de-cab43006d58d] Sent mail to [email protected] (171.6ms) 

它看起來像我有兩個相同的請求,其中一個失敗,從ActiveRecord的'嵌套事務'錯誤(它是AR?類錯誤實際上是::的ActionView ::模板錯誤)......

我沒有看到任何rails source「嵌套事務」 ......

第一個問題是爲什麼在軌兩個請求從同一個客戶和幾乎相同的第二個?

第二個問題是爲什麼這種並行請求確實失敗?

...我已經尋找「嵌套事務」我所有的寶石的來源,我沒有看到它 - 我無法找到該代碼提出這一錯誤:(

+0

是它解決了嗎?如果客戶端實際上有兩個請求並觸發這些請求,您可以檢查devtools嗎? –

+0

現在說得太早了:我已經從rails中刪除了所有數據庫事務,也從rails中使用的存儲過程中刪除了所有數據庫事務,並且我現在沒有5天的這個錯誤,但可能現在的用戶數量較少;它可能是一些未提交的事務導致下次數據庫連接使用的這個錯誤 – Kodak

+0

有趣的是,我重新啓動應用程序(添加一些功能後)我有很多這些:( – Kodak

沙发
0
0

我終於能夠重現上發展這個錯誤:我雙擊造成兩個幾乎同時請求鏈接從升降舵的的PStore來了實際的「嵌套事務」錯誤

解決方案:

  • 使用$ flipper.preload減少翻轉的功能調用數([])與a功能的名字rray並加入5分鐘ActiveSupportCacheStore緩存過的PStore

  • 禁用連續鏈路的使用

要檢查它是否是對生產有效的,但開發試驗看好。

UPDATE1:它只是降低了斷號的錯誤 - 需要通過修補腳蹼啓用上的PStore線程安全選項

UPDATE2:https://github.com/jnunemaker/flipper/pull/334

0
votes
answers
7 views
+10

Rails - 使用ActiveRecord :: Enum的參數錯誤

2

我創建了一個模型Tester,整數列爲tester_type,並聲明模型中的enum變量。Rails - 使用ActiveRecord :: Enum的參數錯誤

class Tester < ApplicationRecord 
    enum tester_type: { junior: 0, senior: 1, group: 2 } 
end 

我得到以下錯誤,而試圖創建/初始化該模型中的對象:

ArgumentError: You tried to define an enum named "tester_type" on the model "Tester", but this will generate a class method "group", which is already defined by Active Record.

所以,我試圖改變tester_typetype_of_tester但它拋出同樣的錯誤:

ArgumentError: You tried to define an enum named "type_of_tester" on the model "Tester", but this will generate a class method "group", which is already defined by Active Record.

我已經搜索的解決方案,我發現這個錯誤是一個常數ENUM_CONFLICT_MESSAGEActiveRecord::Enum類,但不能夠找到這個問題的原因。

請幫幫我。

謝謝。

+0

更改emum的名稱,不要使用testers_type這已被rails使用。 – Sunny

+0

我試着將它改爲'type_of_tester',但是它拋出了相同的錯誤。 –

+0

你也可以粘貼該錯誤。 – Sunny

沙发
0
2

在這種情況下,如果你想使用枚舉,你最好將你的標籤重命名爲其他東西。這不僅限於枚舉 - 許多Active Record功能爲您生成方法,通常也沒有辦法選擇退出這些生成的方法。

然後更改groupanother_name

還是應該遵循這也

enum :kind, [:junior, :senior, :group], prefix: :kind 
band.kind_group? 
板凳
0
1

檢查了這一點。它是您遇到問題的選項組。您可以使用前綴選項,因爲在這個崗位

enum options

地板
0
1

提到可以使用:_prefix:_suffix選擇,當你需要定義具有相同的價值觀或你的情況多枚舉,以避免與已定義的方法發生衝突。如果傳遞值爲true,則方法前綴/後綴爲枚舉的名稱。另外,也可以提供一個自定義的值:

class Conversation < ActiveRecord::Base 
    enum status: [:active, :archived], _suffix: true 
    enum comments_status: [:active, :inactive], _prefix: :comments 
end 

採用上述例子中,爆炸和與相關聯的範圍沿着謂詞方法現在前綴和/或相應後綴:

conversation.active_status! 
conversation.archived_status? # => false 

conversation.comments_inactive! 
conversation.comments_active? # => false 

爲了您情況下,我的建議是使用類似:

class Tester < ApplicationRecord 
    enum tester_type: { junior: 0, senior: 1, group: 2 }, _prefix: :type 
end 

然後你就可以使用這些範圍爲:

tester.type_group! 
tester.type_group? # => true 

Tester.type_group # SELECT "testers".* FROM "testers" WHERE "testers"."tester_type" = $1 [["tester_type", 2]] 
# or, 
Tester.where(tester_type: :group) # SELECT "testers".* FROM "testers" WHERE "testers"."tester_type" = $1 [["tester_type", 2]] 
0
votes
answers
7 views
+10

產品和類別關係

0

試圖在我的應用程序中具有以下關係。產品和類別關係

產品可以屬於許多類別,子類別和子類別。

目前的設計:

Product: 
    has_many :categorizations, dependent: :destroy 
    has_many :categories, through: :categorizations 
    has_many :sub_categories, through: :categorizations 
    has_many :sub_sub_categories, through: :categorizations 

Category: 
    has_many :categorizations 
    has_many :products, through: :categorizations 
    has_many :sub_categories, class_name: 'Category', foreign_key: 'parent_id' 
    belongs_to :parent_category, class_name: 'Category', foreign_key: 'parent_id' 

Categorization: 
    belongs_to :category 
    belongs_to :sub_category, class_name: 'Category', foreign_key: 'sub_category_id' 
    belongs_to :sub_sub_category, class_name: 'Category', foreign_key: 'sub_sub_category_id' 
    belongs_to :product 

產品特定類別的可以被列爲category.products

如何訪問特定產品sub_categorysub_sub_category

我應該做些什麼?

沙发
0
0

將此線路has_many :sub_sub_categories, through: :sub_categories添加到Product型號。

## app/models/product.rb 
has_many :sub_categories 
has_many :categories, through: :sub_categories 
has_many :sub_sub_categories, through: :sub_categories 

如果我是你,我會設計這樣的:

Product: 
    has_many :categorizations 
    has_many :categories, through: :categorizations 

Categorization: 
    belongs_to :product 
    belongs_to :category 

Category: 
    belongs_to :parent, class_name: 'Category', optional: true 
    has_many :children, class_name: 'Category', foreign_key: :parent_id, dependent: :nullify 

    has_many :categorizations 
    has_many :products, through: :categorizations 

注:添加parent_idcategories

+0

謝謝。和上面的設計是罰款或使用自引用關係在'category'而不是'sub_category'更好? – rAzOr

+0

看看我編輯的答案@rAzOr – fongfan999

0
votes
answers
7 views
+10

紅寶石插座 - 運行在socker上的方法

1

我是Ruby插座中的新手。我在服務器項目,我坐了起來插座的服務器如下:紅寶石插座 - 運行在socker上的方法

require 'socket'    
server = TCPServer.open(2000)  
loop {       
    Thread.start(server.accept) do |client| 
    client.puts(Time.now.ctime) 
    client.puts "Closing the connection. Bye!" 
    client.close     
end 

我想從客戶端運行我的方法之一,在我的項目:

require 'socket'  

hostname = 'localhost' 
port = 2000 

s = TCPSocket.open(hostname, port) 

while line = s.gets  
    puts line.chop  
    puts "hey" 

    # call helloWorldMethod() 
end 

s.close     
沙发
0
0
require 'socket'    
server = TCPServer.open(2000)  
loop do       
    Thread.start(server.accept) do |client| 
    client.puts(Time.now.ctime) 
    client.puts "Closing the connection. Bye!" 
    client.close     
    end 
end 

我相信您的解決方案是在??

,我發現這個文檔中關於ruby socket programming

微型網頁瀏覽器

我們可以使用套接字庫來實現任何Internet協議。這裏,例如,是抓取網頁

取決於你的路由你可能要調整URL的內容的代碼,它chould是www.yourwebsite.com/users

require 'socket' 

host = 'www.tutorialspoint.com'  # The web server 
port = 80       # Default HTTP port 
path = "/index.htm"     # The file we want 

這是HTTP請求我們發送獲取文件

,您可以在HTTP postput要求

改變你的要求
request = "GET #{path} HTTP/1.0

" 

socket = TCPSocket.open(host,port) # Connect to server 
socket.print(request)    # Send request 
response = socket.read    # Read complete response 
# Split response at first blank line into headers and body 
headers,body = response.split("

", 2) 
print body       # And display it 

要實現類似的Web客戶端,您可以使用像Net :: HTTP這樣的預建庫來處理HTTP。以下是代碼,代碼相當於以前的代碼 -

require 'net/http'     # The library we need 
host = 'www.tutorialspoint.com'  # The web server 
path = '/index.htm'     # The file we want 

http = Net::HTTP.new(host)   # Create a connection 
headers, body = http.get(path)  # Request the file 
if headers.code == "200"   # Check the status code 
    print body       
else         
    puts "#{headers.code} #{headers.message}" 
end