ruby-on-rails-3.1

Rails 3.1 and jquery-ui assets

我的梦境 提交于 2019-11-27 10:10:27
This was asked in another question, but none of the solutions appear to work for me in 3.1rc1. I'm trying to use the new assets stuff in rails 3.1 - I have the files: ./vendor/assets/stylesheets/jquery-ui-1.8.13.custom.css ./vendor/assets/javascripts/jquery-ui-1.8.13.custom.min.js I then added: //= require jquery-ui to app/assets/javascripts/application.js *= require jquery-ui to app/assets/stylesheets/application.css The jquery-ui javascript file loads just fine, but the css file says: Sprockets::FileNotFound (couldn't find file 'jquery-ui' (in /home/xanview2/xancar/app/assets/stylesheets

Rails 3.1 is very slow in development-mode because of assets, what to do?

邮差的信 提交于 2019-11-27 09:58:44
问题 After I added Sprockets, Rails is loading very slow in development mode, what should I do to speed it up? 回答1: Take a look at https://github.com/wavii/rails-dev-tweaks. Rails is running all of the to_prepare hooks on every Sprockets asset request in development mode. This includes things like auto-(re)loading your code, and various gems sneak work in there too. rails-dev-tweaks disables to_prepare & reloading on any asset request (and a few others - read the first part of its README ). Speeds

Rails: Force empty string to NULL in the database

試著忘記壹切 提交于 2019-11-27 09:57:48
问题 Is there an easy way (i.e. a configuration) to force ActiveRecord to save empty strings as NULL in the DB (if the column allows)? The reason for this is that if you have a NULLable string column in the DB without a default value, new records that do not set this value will contain NULL, whereas new records that set this value to the empty string will not be NULL, leading to inconsistencies in the database that I'd like to avoid. Right now I'm doing stuff like this in my models: before_save

When to use self in Model?

笑着哭i 提交于 2019-11-27 09:55:44
问题 Question: when do I need to use self in my models in Rails? I have a set method in one of my models. class SomeData < ActiveRecord::Base def set_active_flag(val) self.active_flag = val self.save! end end When I do this, everything works fine. However, when I do this: class SomeData < ActiveRecord::Base def set_active_flag(val) active_flag = val save! end end The active_flag value doesn't change, rather it fails silently. Can someone explain? I can't find any duplicates, but if someone finds

How to make Rails 3.1 use SASS (Over SCSS) as the default?

☆樱花仙子☆ 提交于 2019-11-27 09:31:44
问题 Having a hard time figuring out how to make SASS, not SCSS, as the default for stylesheets. I've tried making a sass_config.rb file with this: Sass::Plugin.options[:syntax] = :sass Sass::Plugin.options[:style] = :compressed I've also tried adding that to the environment.rb file. Either way I get this error: .../config/environment.rb:7:in `<top (required)>': uninitialized constant Sass::Plugin (NameError) 回答1: For rails 3.1.rc4, you could set the config: config.sass.preferred_syntax = :sass in

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

允我心安 提交于 2019-11-27 08:24:42
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}") # SELECT "users".* FROM "users" ORDER BY email; DELETE from users; -- asc now we have no more users :( I

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

心不动则不痛 提交于 2019-11-27 08:12:43
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? Comment out gem "coffee-script" in your Gemfile Use .js instead of .js.coffee for your javascript files Not sure if this counts for Rails 3.1 but in 4 you should also set the javascript_engine to :js in application.rb to instruct generators to create .js files instead of .js.coffee . config.generators do

“Certificate verify failed” OpenSSL error when using Ruby 1.9.3

心已入冬 提交于 2019-11-27 07:39:12
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: certificate verify failed (OpenSSL::SSL::SSLError) I understand the Ruby language interpreter is using

Can we call a Controller's method from a view (as we call from helper ideally)?

こ雲淡風輕ζ 提交于 2019-11-27 07:10:52
In Rails MVC, can you call a controller's method from a view (as a method could be called call from a helper)? If yes, how? sailor Here is the answer: class MyController < ApplicationController def my_method # Lots of stuff end helper_method :my_method end Then, in your view, you can reference it in ERB exactly how you expect with <% or <%= : <% my_method %> Pavling You possibly want to declare your method as a "helper_method", or alternatively move it to a helper. What do helper and helper_method do? Wahaj Ali Haven't ever tried this, but calling public methods is similar to: @controller

Access Asset Path from Rails Controller

风格不统一 提交于 2019-11-27 06:47:19
I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't inside a controller. I could access directly using "#{Rails.root}/app/assets/javascripts/configuration.yml" but when deploying the filename gets the digest string appended. How can I get the same path from a controller? ActionController::Base.helpers.asset_path("configuration.yml") Might also be good to put configuration.yml in a different folder to