ruby-on-rails-3

Rails current_page? “fails” when method is POST

一笑奈何 提交于 2020-12-25 03:50:50
问题 I have a really simple problem. I have a page of reports and each report has its own tab. I'm using current_page? to determine which tab should be highlighted. When I submit any report, current_page? doesn't seem to work anymore, apparently because the request method is POST . Is this the intended behavior of current_page? I have a hard time imagining why that would be the case. If it is, how do people normally get around this problem? Here's an example of a current_page? call: <li><%= link

Rails current_page? “fails” when method is POST

喜欢而已 提交于 2020-12-25 03:50:10
问题 I have a really simple problem. I have a page of reports and each report has its own tab. I'm using current_page? to determine which tab should be highlighted. When I submit any report, current_page? doesn't seem to work anymore, apparently because the request method is POST . Is this the intended behavior of current_page? I have a hard time imagining why that would be the case. If it is, how do people normally get around this problem? Here's an example of a current_page? call: <li><%= link

How can I set up reserved word for particular column in validation?

核能气质少年 提交于 2020-12-12 10:22:39
问题 I have a model called Community and it has a column called name I use this name in sub-domain. For example, when a user access to http://rockstar.test-sample.com , it show the same content as http://test-sample.com/community/rockstar obviously, this name shouldn't be www How can I prohibit www if I'm stating that in models/community.rb ? 回答1: You might want to spend some time with the Active Record Validations Guide: 2.4 exclusion This helper validates that the attributes' values are not

trying to solve /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError) led to bad interpreter: /usr/local/opt/python/bin/python2.7

梦想与她 提交于 2020-12-04 05:26:32
问题 After a brew upgrade, I couldn’t run any of my Ruby on Rails apps anymore. I got this error message: : dlopen(/Users/ll/.rbenv/versions/2.6.2/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError) Referenced from: /Users/ll/.rbenv/versions/2.6.2/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle Reason: image not found - /Users/ll/.rbenv/versions/2.6.2/lib/ruby/2.6.0/x86_64-darwin18/openssl.bundle So I tried brew switch

Why use GemSpec + GemFile when checking for dependencies?

亡梦爱人 提交于 2020-12-02 07:21:08
问题 Whenever developing gems, I don't see any reasons why Gemfile is not directly inspected for dependencies. Indeed, why use a .gemspec file in order to list them ? Is there a real benefit ? 回答1: Well that's because the Gemfile isn't a file from Rubygems, but a file from Bundler. So the Rubygem developers would have to extend their used files in order to support Gemfile. Since there already is the .gemspec file, there is no valid reason why they should. (there are enough gems which do well

Why use GemSpec + GemFile when checking for dependencies?

你说的曾经没有我的故事 提交于 2020-12-02 07:20:24
问题 Whenever developing gems, I don't see any reasons why Gemfile is not directly inspected for dependencies. Indeed, why use a .gemspec file in order to list them ? Is there a real benefit ? 回答1: Well that's because the Gemfile isn't a file from Rubygems, but a file from Bundler. So the Rubygem developers would have to extend their used files in order to support Gemfile. Since there already is the .gemspec file, there is no valid reason why they should. (there are enough gems which do well

Why do date helpers not work in Rails console?

醉酒当歌 提交于 2020-12-01 08:02:50
问题 I have a datetime attribute on a record: 1.9.3p194 :024> f.last_contact => Thu, 11 Aug 2011 00:00:00 UTC +00:00 But when I try time_ago_in_words at the console, it doesn't work: > time_ago_in_words(f.last_contact) NoMethodError: undefined method `time_ago_in_words' for main:Object I also tried distance_of_time_in_words which the docs say should work with Time, Date & DateTime objects. > to_time = Time.now => 2012-09-08 12:22:16 -0500 > distance_of_time_in_words(f.last_contact, to_time)

What is the difference between Rails.cache.clear and rake tmp:cache:clear?

梦想的初衷 提交于 2020-11-30 02:45:28
问题 Are the two commands equivalent? If not, what's the difference? 回答1: The rake task only clears out files that are stored on the filesystem in "#{Rails.root}/tmp/cache" . Here's the code for that task. namespace :cache do # desc "Clears all files and directories in tmp/cache" task :clear do FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) end end https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30 Rails.cache.clear will do different

What is the difference between Rails.cache.clear and rake tmp:cache:clear?

若如初见. 提交于 2020-11-30 02:45:08
问题 Are the two commands equivalent? If not, what's the difference? 回答1: The rake task only clears out files that are stored on the filesystem in "#{Rails.root}/tmp/cache" . Here's the code for that task. namespace :cache do # desc "Clears all files and directories in tmp/cache" task :clear do FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) end end https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30 Rails.cache.clear will do different

What is the difference between Rails.cache.clear and rake tmp:cache:clear?

喜夏-厌秋 提交于 2020-11-30 02:44:59
问题 Are the two commands equivalent? If not, what's the difference? 回答1: The rake task only clears out files that are stored on the filesystem in "#{Rails.root}/tmp/cache" . Here's the code for that task. namespace :cache do # desc "Clears all files and directories in tmp/cache" task :clear do FileUtils.rm_rf(Dir['tmp/cache/[^.]*']) end end https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30 Rails.cache.clear will do different