ruby-on-rails-2

What is the best possible way to avoid the sql injection?

隐身守侯 提交于 2021-01-29 20:50:40
问题 I am using ruby 1.8.7 and rails 2.3.2 The following code is prone to sql injection params[:id] = "1) OR 1=1--" User.delete_all("id = #{params[:id]}") My question is by doing the following will be the best solution to avoid sql injection or not. If not then what is the best way to do so? User.delete_all("id = #{params[:id].to_i}") 回答1: What about: User.where(id: params[:id]).delete_all Ok sorry for Rails 2.x its: User.delete_all(["id = ?", params[:id]]) Check doc Btw, be sure you want to use

syntax error, file to import not found or unreadable: compass_twitter_bootstrap

半腔热情 提交于 2020-01-14 04:35:28
问题 I would like to use compass_twitter_bootstrap. Here is what I did: 1) My Gemfile: gem 'compass' gem 'compass-rails' gem 'compass_twitter_bootstrap' 2) My compass.rb under config folder: require 'compass_twitter_bootstrap' project_type = :rails http_path = "/" css_dir = "public/stylesheets" sass_dir = "public/stylesheets/sass" 3) I created a scss file under public/stylesheets/sass and I aded @import "compass_twitter_bootstrap"; on the top of the file. 4) I also added the stylesheet_link_tag

Rails: get #beginning_of_day in time zone

☆樱花仙子☆ 提交于 2020-01-12 03:13:05
问题 I have a default time zone setup for the rails application. And an instance of the Date object. How can I get make Date#beginning_of_day to return the beginning of the day in the specified time zone, but not my local timezone. Is there any other method to get beginning of the day time in the specified timezone for the given date? date = Date.new(2014,10,29) zone = ActiveSupport::TimeZone.new('CET') date.foo(zone) # should return "Wed, 29 Oct 2014 00:00:00 CET +01:00" zone = ActiveSupport:

Rails: get #beginning_of_day in time zone

风流意气都作罢 提交于 2020-01-12 03:11:14
问题 I have a default time zone setup for the rails application. And an instance of the Date object. How can I get make Date#beginning_of_day to return the beginning of the day in the specified time zone, but not my local timezone. Is there any other method to get beginning of the day time in the specified timezone for the given date? date = Date.new(2014,10,29) zone = ActiveSupport::TimeZone.new('CET') date.foo(zone) # should return "Wed, 29 Oct 2014 00:00:00 CET +01:00" zone = ActiveSupport:

application wide global variable

人盡茶涼 提交于 2020-01-02 00:49:13
问题 In Rails , where should I define the variable which can be recognized by every layer of Rails stacks. For example, I would like to have a CUSTOMER_NAME='John' variable which can be accessed in helper , rake task, controller and model . Where should I define this variable in Rails app? I am using Rails v2.3.2 回答1: In an initializer in /app/config/initializers all .rb files in here get loaded, I usually create one called preferences.rb for things like this. See: http://guides.rubyonrails.org

Why isn't Rails recognizing nil if blank in my form?

偶尔善良 提交于 2019-12-25 07:09:38
问题 I'm reworking a Rails 2 website. Right now, I'm getting an error, and I think it's because a value is being submitted as blank instead of .nil. However, my attempts to keep it nil don't seem to be working. I appreciate any help you have to offer. From Model, based on Make blank params[] nil NULL_ATTRS = %w( start_masterlocation_id ) before_save :nil_if_blank protected def nil_if_blank NULL_ATTRS.each { |attr| self[attr] = nil if self[attr].blank? } end View I've got jQuery that adds a value

Downgrading a Rails 3 App to Rails 2

纵然是瞬间 提交于 2019-12-25 05:18:12
问题 I've run into a problem today. I've spent the past couple of months building a fairly intensive Rails 3 App that uses all the latest versions of every gem I need. I've just been informed that I can't use anything new. I'll be adding my project in with a bunch of others which use older versions of everything. We can't upgrade the existing, we can only downgrade mine. With that said, I need to downgrade pretty much everything I've done. Here's a list of what I'm using currently (via gem list ):

Grouping and counting information in table relationship issue

折月煮酒 提交于 2019-12-25 02:47:15
问题 I did an app to show a the last net_insurance and count in Insurance Financing but i'm trying to group and count when is expired and not expired Here my tables |policies| |id| |num_policy| 1 12345 2 54654 |insurances| |id| |id_policy| |net_insurance| 1 1 1000 2 2 2000 3 2 3000 4 1 5000 |insurance_financing| |id| |id_ensurance| |number| |expiration_date| 1 2 9888 26/10/2013 2 2 1444 27/10/2013 3 4 2444 28/10/2013 4 4 1445 01/11/2013 |trying to obtain| |num_policy| |last_net_insurance| |count

Grouping and counting information in table relationship issue

房东的猫 提交于 2019-12-25 02:47:08
问题 I did an app to show a the last net_insurance and count in Insurance Financing but i'm trying to group and count when is expired and not expired Here my tables |policies| |id| |num_policy| 1 12345 2 54654 |insurances| |id| |id_policy| |net_insurance| 1 1 1000 2 2 2000 3 2 3000 4 1 5000 |insurance_financing| |id| |id_ensurance| |number| |expiration_date| 1 2 9888 26/10/2013 2 2 1444 27/10/2013 3 4 2444 28/10/2013 4 4 1445 01/11/2013 |trying to obtain| |num_policy| |last_net_insurance| |count