ruby-on-rails-3

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

Rails custom route with constraints - regexp anchor characters are not allowed in routing requirements

╄→гoц情女王★ 提交于 2021-02-07 11:29:11
问题 I have the following route: get 'users/:user_id/:name', to: 'profiles#show', :constraints => { :name => /[a-zA-Z0-9_]+$/ }, as: 'user_profile' Which produces the error: Regexp anchor characters are not allowed in routing requirements: /[a-zA-Z0-9_]+$/ So I get that the ^ character isn't allowed, but not sure what character is producing this particular routing error. 回答1: In regex we have two anchors: Beginning of line/string ^ End of line/string $ Try to remove $ from the pattern and you

: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

Garbage collector in Ruby on Rails?

元气小坏坏 提交于 2021-02-07 07:10:21
问题 I have tried to Google a lot about Rails Garbage collector, but I didn't get a reliable answer. Has anyone got a source to show how garbage collection is implemented in Rails? How can we control it? 回答1: Rails is a framework, not a language. The language behind Rails is called Ruby. This means there is no notion of Garbage Collector in Rails. You should search for documentation about the Ruby Garbage Collector. You can start from the Ruby GC module. The GC module provides an interface to Ruby

Garbage collector in Ruby on Rails?

丶灬走出姿态 提交于 2021-02-07 07:07:02
问题 I have tried to Google a lot about Rails Garbage collector, but I didn't get a reliable answer. Has anyone got a source to show how garbage collection is implemented in Rails? How can we control it? 回答1: Rails is a framework, not a language. The language behind Rails is called Ruby. This means there is no notion of Garbage Collector in Rails. You should search for documentation about the Ruby Garbage Collector. You can start from the Ruby GC module. The GC module provides an interface to Ruby

How to change ActiveRecord's table name during runtime

喜你入骨 提交于 2021-02-07 05:51:53
问题 I am changing the table_name_prefix during running of a rails application (might sound weird, but really that's what I want). When the table_name_prefix changes for the ActiveRecord I reset the table names ( table_name and quoted_table_name ) by calling reset_table_name , and they change.. however I have another issue. If the table name changes, after calling such a thing like count or a find the ActiveRecord object still operates with the table, which was used before. How can reach to reset

Rails 3 passing a rails array to javascript function which uses a javascript array

流过昼夜 提交于 2021-02-07 04:52:27
问题 I am trying to pass a rails array to a javascript function. The function will then use the array values in javascript so I need to keep it an array. Here is how I am passing my array: "graphit([<%=@mpg_values.join(",") %>])" This produces this in the HTML "graphit([#<Mile:0x6ff0cf0>,#<Mile:0x6ff0c18>,#<Mile:0x6ff0b58>])" Which are not the values, they should be decimal numbers. I assume this is because it is a reference to the array so that I why I am getting the messed up values. If I do

How to stop a heroku server?

一个人想着一个人 提交于 2021-02-07 03:22:33
问题 I have a staging server hosted on heroku, I just want to bring it down, but not destroy the app. How can I do it? Do I have any command like 'heroku stop' like 'heroku restart' for restarting? OR Is there a way to automate the server to turn off itself when it exceeds the 750 hr free usage? Actually I don't want the server so I am trying to stop it, or leave it for the free hours. 回答1: You can scale individual non-web processes down to zero quite happily: $ heroku ps:scale worker=0 $ heroku

How to stop a heroku server?

 ̄綄美尐妖づ 提交于 2021-02-07 03:20:29
问题 I have a staging server hosted on heroku, I just want to bring it down, but not destroy the app. How can I do it? Do I have any command like 'heroku stop' like 'heroku restart' for restarting? OR Is there a way to automate the server to turn off itself when it exceeds the 750 hr free usage? Actually I don't want the server so I am trying to stop it, or leave it for the free hours. 回答1: You can scale individual non-web processes down to zero quite happily: $ heroku ps:scale worker=0 $ heroku