ruby-on-rails-4.2

How to use Rails with uppercase column name?

六月ゝ 毕业季﹏ 提交于 2020-05-29 05:00:50
问题 I have the following as part of an AR query: .having('COUNT(foo.id) > bar.maxUsers') This generates an error: ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column bar.maxusers does not exist ^ HINT: Perhaps you meant to reference the column "bar.maxUsers". I am referencing the column bar.maxUsers . So, apparently AR downcases the query. How to suppress this behavior? Rails 4.2.10 PostgreSQL EDIT: SQL: SELECT ... HAVING COUNT(foo.id) > bar.maxUsers So it is happening after the to

Rails 4.2.0.beta2 - Can't connect to LocalHost?

半城伤御伤魂 提交于 2020-01-13 10:29:16
问题 I installed Rails 4.2.0.beta2 per the instructions in RailsTutorial.org 3rd Edition (the one that just came out). I'm not using the cloudIDE and am instead using Ubuntu Trusty 32 via Vagrant on a Windows 7 host with RVM. Did rails _4.2.0.beta2_ new hello_app and then pasted in his gemfile sample. After that, I ran: $ bundle install $ rails s Server starts fine, however when I try to connect to localhost:3000 I get "Server Not Found" Weirder still, I have a couple other Rails starter projects

How can I avoid Devise from requires authentication from within an engine?

﹥>﹥吖頭↗ 提交于 2020-01-05 23:29:36
问题 I'm using Devise for athentication in my main application and I have built an API (for a PABX) using "http_basic_authenticate_with" and it's working well when I add before_action :authenticate_user!, except: [:method_name] to my controller. I'm doing that because except: [:method_name] will not require a logged user session on Devise and I just want to use basic authenticate for those API controllers. config/routes.rb (main application) scope module: 'api' do scope module: 'pabx' do scope '

How can I avoid Devise from requires authentication from within an engine?

蓝咒 提交于 2020-01-05 23:27:53
问题 I'm using Devise for athentication in my main application and I have built an API (for a PABX) using "http_basic_authenticate_with" and it's working well when I add before_action :authenticate_user!, except: [:method_name] to my controller. I'm doing that because except: [:method_name] will not require a logged user session on Devise and I just want to use basic authenticate for those API controllers. config/routes.rb (main application) scope module: 'api' do scope module: 'pabx' do scope '

Jbuilder Rails caching is slower

你。 提交于 2020-01-01 05:16:12
问题 I've tried to use caching with collections (with multiple solutions) the problem is that when ever I try caching the response become slower consider the following example of a collection that renders 2 partials for every item in it (around 25 item) json.data do json.array! @organizations do |organization| json.partial! 'api/v1/organizations/organization', organization: organization json.partial! 'api/v1/organizations/links', organization: organization end end without caching the average

rspec before(:each) hook - conditionally apply

╄→гoц情女王★ 提交于 2019-12-25 04:29:15
问题 I have following in my rails_helper.rb : RSpec.configure do |config| # ... config.before(:each, type: :controller) do # SOMETHING end end I want to define directories, to which this SOMETHING will be applicable (in my case ONLY to files under spec/controllers/api directory). Any chance to achieve that? 回答1: You can use a more specialized name for your RSpec filter: RSpec.configure do |config| # ... config.before(:each, :subtype => :controllers_api) do # SOMETHING end end And then in your

Rails internationalization is not working in production mode

送分小仙女□ 提交于 2019-12-24 18:11:08
问题 I have a non-AR model, which I use for a form/composition object. There are lots input fields, which I collect in order to do some data manipulation inside AR transaction. I use I18n for internationalization. yml: pl: activemodel: attributes: catalog/checkout: name: Imię form: = f.input :name, required: true, label: I18n.t(:'.activemodel.attributes.catalog/checkout.name') The issue is that in development and production modes (locally) I see the input having proper label taken from config

Rails internationalization is not working in production mode

丶灬走出姿态 提交于 2019-12-24 18:10:37
问题 I have a non-AR model, which I use for a form/composition object. There are lots input fields, which I collect in order to do some data manipulation inside AR transaction. I use I18n for internationalization. yml: pl: activemodel: attributes: catalog/checkout: name: Imię form: = f.input :name, required: true, label: I18n.t(:'.activemodel.attributes.catalog/checkout.name') The issue is that in development and production modes (locally) I see the input having proper label taken from config

How to show some HTML entities on title tag using Rails

感情迁移 提交于 2019-12-24 18:02:10
问题 I'm running Rails 4.2.x and I have the following problem. The <title> of some pages are generated from user content. So I have to use the sanitize Rails helpers to properly clean it up. But if the user writes something like "A & B", the title shown in browser is A & B which is wrong. What's the correct way of escaping user content on the <title> tag using Rails? At least some special characters should be included... 回答1: We can use CGi also title = "A & B" => "A & B" string = CGI.escapeHTML

How to show some HTML entities on title tag using Rails

会有一股神秘感。 提交于 2019-12-24 18:02:07
问题 I'm running Rails 4.2.x and I have the following problem. The <title> of some pages are generated from user content. So I have to use the sanitize Rails helpers to properly clean it up. But if the user writes something like "A & B", the title shown in browser is A & B which is wrong. What's the correct way of escaping user content on the <title> tag using Rails? At least some special characters should be included... 回答1: We can use CGi also title = "A & B" => "A & B" string = CGI.escapeHTML