ruby-on-rails-3.1

rails 3 activerecord order - what is the proper sql injection work around?

戏子无情 提交于 2019-11-26 14:08:11
问题 let us say I have a list page of users and you can sort by the different columns, when clicking 'email' it will pass sort_by=email sort_direction=asc or desc sort_by = "email" # really params[:sort_by] sort_direction = "asc" # really params[:sort_direction] User.order("#{sort_by} #{sort_direction}") # SELECT "users".* FROM "users" ORDER BY email asc so that works as expected, however if we change the sort_by sort_by = "email; DELETE from users; --" User.order("#{sort_by} #{sort_direction}") #

How can I completely disable CoffeeScript in a Rails 3.1 app?

家住魔仙堡 提交于 2019-11-26 14:04:07
问题 At the moment when I generate a new controller, Rails also generates a .js.coffee file for the controller as well. As I don't use CoffeeScript I want Rails instead generate .js files for me. Is it enough to comment out the coffee-rails gem to completely disable CofeeScript in a Rails 3.1 app? 回答1: Comment out gem "coffee-script" in your Gemfile Use .js instead of .js.coffee for your javascript files 回答2: Not sure if this counts for Rails 3.1 but in 4 you should also set the javascript_engine

Using Rails 3.1 assets pipeline to conditionally use certain css

僤鯓⒐⒋嵵緔 提交于 2019-11-26 13:53:15
I’m in the process of building my first solo Rails app using Rails 3.1.rc5. My problem is that I want to have my site render the various CSS files conditionally. I’m using Blueprint CSS and I’m trying to have sprockets/rails render screen.css most of the time, print.css only when printing, and ie.css only when the site is accessed from Internet Explorer. Unfortunately, the default *= require_tree command in the application.css manifest includes everything in the assets/stylesheets directory and results in an unpleasant CSS jumble. My current workaround is a sort of brute-force method where I

“Certificate verify failed” OpenSSL error when using Ruby 1.9.3

不打扰是莪最后的温柔 提交于 2019-11-26 13:45:31
问题 I'm using Ruby 1.9.3p0 on Mac OS 10.6.8 (installed using rvm). When I attempt to create a new Rails application using an application template hosted on GitHub, with this (for example): $ rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-devise-template.rb -T -O I get this error message: /Users/me/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B:

Rails 3.1 asset precompilation - include all javascript files

折月煮酒 提交于 2019-11-26 12:58:17
问题 I want Rails 3.1 to pick up more of my assets for precompilation. In particular, the default matcher for compiling files doesn\'t add .js files from vendor/assets/javascripts . I can just add the assets to the config.assets.precompile list, but this seems annoying. I don\'t want to refer to them in the application.js manifest, because I don\'t want them included in all pages. In summary, any way to request that all .js files found in vendor/assets/javascripts get precompiled by rake assets

Rails 3.1 asset pipeline: how to load controller-specific scripts?

独自空忆成欢 提交于 2019-11-26 12:38:30
If I generate a new controller in Rails 3.1, also a javascript file with the name of the controller will added automatically. Firstly, I thought this javascript file will used only, when the related controller is called. By default there is the instruction //= require_tree . in the application.js -file, that include every javascript file on it's tree. How could I load only the controller specific script? Nguyen Chien Cong To load only the necessary name_of_the_js_file.js file: remove the //=require_tree from application.js keep your js file (that you want to load when a specific page is loaded

Convert HTML to word file ?

让人想犯罪 __ 提交于 2019-11-26 09:55:41
问题 How to convert ruby file in word file i.e (docx file). For pdf, we prawn gem. But is there any gem for word file. I am trying to convert my html file in word file so that it can be editable for user too. What should do in that case ? I was planning to convert that file in word file. Will it be possible or not. 回答1: If you are using Rails: in initializers/mime_types.rb: Mime::Type.register 'application/vnd.ms-word', :msword in your controller: say you want to export show action: def show @item

Rails 3.1: Engine vs. Mountable App

别来无恙 提交于 2019-11-26 08:57:36
问题 Can someone help me understand the differences between a Rails Engine and a Mountable app? In Rails 3.1, you can create either one with the \"rails new plugin _ __ \" command. rails plugin new forum --full # Engine rails plugin new forum --mountable # Mountable App When would you want to use one versus the other? I know you can package an Engine as a gem, for one. Is that not the case for Mountable Apps? What other differences are there? 回答1: I have noticed the following: Full Engine With a

Rails - Could not find a JavaScript runtime?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 08:50:40
问题 I created a new Rails project using rails 3.1.0.rc4 on my local machine but when I try to start the server I get: Could not find a JavaScript runtime. See here for a list of available runtimes. ( ExecJS::RuntimeUnavailable ) Note: This is not about Heroku. 回答1: Installing a javascript runtime library such as nodejs solves this To install nodejs on ubuntu, you can type the following command in the terminal: sudo apt-get install nodejs To install nodejs on systems using yum, type the following

Subqueries in activerecord

喜夏-厌秋 提交于 2019-11-26 07:26:39
问题 With SQL I can easily do sub-queries like this User.where(:id => Account.where(..).select(:user_id)) This produces: SELECT * FROM users WHERE id IN (SELECT user_id FROM accounts WHERE ..) How can I do this using rails\' 3 activerecord/ arel/ meta_where? I do need/ want real subqueries, no ruby workarounds (using several queries). 回答1: Rails now does this by default :) Message.where(user_id: Profile.select("user_id").where(gender: 'm')) will produce the following SQL SELECT "messages".* FROM