ruby

How can I call a channel method in a rails controller?

谁都会走 提交于 2021-02-07 11:59:14
问题 I have an ActionCable method that subscribes the user. If a new convo is started, I want to subscribe the user to the new channel as well. I can't figure out the proper syntax for calling a channel method in a controller. UPDATE: The issue is that the messages are appended to the chatbox when sent, but when the first message, is sent, the websocket connection is not established yet, and therefore it looks to the user as if the message was not sent (because it's not being appended). channel

How to get current context name of rspec?

╄→尐↘猪︶ㄣ 提交于 2021-02-07 11:17:44
问题 if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with specdocs, but how to get it inside itself? 回答1: describe 'Foo' do describe 'Sub-Foo' do it "should Bar" do |example| puts "#{self.class.description} #{example.description}" end end end The above code

How to get current context name of rspec?

穿精又带淫゛_ 提交于 2021-02-07 11:17:16
问题 if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with specdocs, but how to get it inside itself? 回答1: describe 'Foo' do describe 'Sub-Foo' do it "should Bar" do |example| puts "#{self.class.description} #{example.description}" end end end The above code

How to uninstall ruby installed by ruby-install

左心房为你撑大大i 提交于 2021-02-07 11:16:27
问题 I have many rubies installed by ruby-install under ~/.rubies : ls .rubies ruby-1.9.3-p545 ruby-2.0.0-p598 ruby-2.1.3 ruby-2.1.5 ruby-2.0.0-p451 ruby-2.1.2 ruby-2.1.4 ruby-2.2.0 I want to uninstall one of the ruby installed by ruby-install, How do I do that? 回答1: Unfortunately appears that ruby-install just downloads and compiles Ruby, with no option to remove it, unlike RVM or rbenv . So, probably you'll need to run some manual commands here to delete all installed files. 1. Locate it Usually

How do I stub a method to raise an error using Ruby MiniTest?

家住魔仙堡 提交于 2021-02-07 11:13:57
问题 I'm trying to test a Rails controller branch that is triggered when the model method raises an error. def my_controller_method @my_object = MyObject.find(params[:id]) begin result = @my_object.my_model_method(params) rescue Exceptions::CustomError => e flash.now[:error] = e.message redirect_to my_object_path(@my_object) and return end # ... rest irrelevant end How can I get a Minitest stub to raise this Error? it 'should show redirect on custom error' do my_object = FactoryGirl.create(:my

:remote => true confusion with form_for

▼魔方 西西 提交于 2021-02-07 10:14:56
问题 I'm just learning Rails and would appreciate any help. I've looked at probably 10 tutorials for :remote => true on form_for and they all seem to copy each other (equally confusing). This tutorial is one of them: http://tech.thereq.com/post/18910961502/rails-3-using-form-remote-true-with-jquery-ujs My web app is pretty much all on one page, and my 'submit form' is inside a pop-up lightbox. This means that the form_for code is actually within my index.html.erb. It also means a new @playlist

:remote => true confusion with form_for

眉间皱痕 提交于 2021-02-07 10:14:40
问题 I'm just learning Rails and would appreciate any help. I've looked at probably 10 tutorials for :remote => true on form_for and they all seem to copy each other (equally confusing). This tutorial is one of them: http://tech.thereq.com/post/18910961502/rails-3-using-form-remote-true-with-jquery-ujs My web app is pretty much all on one page, and my 'submit form' is inside a pop-up lightbox. This means that the form_for code is actually within my index.html.erb. It also means a new @playlist

Ruby system call (on windows) without a popup command prompt

社会主义新天地 提交于 2021-02-07 09:41:58
问题 I am trying to tidy up a process that uses multiple system calls from inside a ruby script executed using rubyw.exe (1.8.7). As far as I can understand the main reason for rubyw.exe is that it doesn't pop up a command prompt to distract the user. However it appears that the system calls from within that process still do generate these popups which is very distracting for the users of this process script. Does anyone know how to do this? There are lots of questions similar to this on SO but

Rails 5 - save rolls back because nested models parent model is not being saved before child model

天大地大妈咪最大 提交于 2021-02-07 09:33:39
问题 Ok folks, Rails 5 has really had its nuances differing from Rails 4. What I have going on is that every time I click the submit button on the form it reloads with the error Profile user must exist and Profile user can't be blank . The form loads fine including the nested models form, but for what ever reason it is failing to save the parent model before attempting to save the child model with the following output to the console: Puma starting in single mode... * Version 3.7.0 (ruby 2.2.6-p396

Ruby's body_permitted? method giving “NoMethodError”

血红的双手。 提交于 2021-02-07 09:32:44
问题 I was going through ruby's Net::HTTP class. Every time I run this code from Net::HTTP doc #!/usr/bin/ruby require 'net/http' uri = URI('http://example.com/index.html') res = Net::HTTP.get_response(uri) # Headers res['Set-Cookie'] # => String res.get_fields('set-cookie') # => Array res.to_hash['set-cookie'] # => Array puts "Headers: #{res.to_hash.inspect}" # Status puts res.code # => '200' puts res.message # => 'OK' puts res.class.name # => 'HTTPOK' # Body puts res.body if res.response_body