ruby-on-rails-3

Preventing HTML character entities in locale files from getting munged by Rails3 xss protection

北城余情 提交于 2019-12-31 11:43:03
问题 We're building an app, our first using Rails 3, and we're having to build I18n in from the outset. Being perfectionists, we want real typography to be used in our views: dashes, curled quotes, ellipses et al. This means in our locales/xx.yml files we have two choices: Use real UTF-8 characters inline. Should work, but hard to type, and scares me due to the amount of software which still does naughty things to unicode. Use HTML character entities (’ — etc). Easier to type, and probably more

Preventing HTML character entities in locale files from getting munged by Rails3 xss protection

雨燕双飞 提交于 2019-12-31 11:41:18
问题 We're building an app, our first using Rails 3, and we're having to build I18n in from the outset. Being perfectionists, we want real typography to be used in our views: dashes, curled quotes, ellipses et al. This means in our locales/xx.yml files we have two choices: Use real UTF-8 characters inline. Should work, but hard to type, and scares me due to the amount of software which still does naughty things to unicode. Use HTML character entities (’ — etc). Easier to type, and probably more

Rails 3.2, RSpec, Factory Girl : NameError: uninitialized constant Factory

社会主义新天地 提交于 2019-12-31 10:59:05
问题 Ive been following this introductory to Rails testing and Ive run into an issue I cant seem to find the solution to. Im very familiar with Rails but this is my first foray into testing. Anyhow, I have a very basic model test, not even fully implemented and when I try and run rspec spec/models/admin_spec.rb . I get the following error in the Admin has a valid factory line (full code below) Admin has a valid factory Failure/Error: Factory.create(:admin).should be_valid NameError: uninitialized

Rails Migration to make a column null => true

烂漫一生 提交于 2019-12-31 10:56:52
问题 I had originally created a table with column as t.string "email", :default => "", :null => false The requirement has changed and now I need to allow email to be null. How can I write a migration to make :null => true 回答1: Try: change_column :table_name, :email, :string, :null => true 回答2: I could not get the above solution to work with Active Record 4.0.8 and Postgresql 9.3 However change_column_null worked perfectly. change_column_null :users, :email, true The reverse has a nice option to

Create another model upon user new registration in devise

时间秒杀一切 提交于 2019-12-31 10:54:57
问题 I'm using devise to do the new user registration. Right after a new user is created, I would also like to create a profile for that user. My create method in the registrations_controller.rb is as follows: class RegistrationsController < Devise::RegistrationsController def create super session[:omniauth] = nil unless @user.new_record? # Every new user creates a default Profile automatically @profile = Profile.create @user.default_card = @profile.id @user.save end But, it is not creating a new

Active Admin Ruby on rails Dashboard Controller Error

坚强是说给别人听的谎言 提交于 2019-12-31 10:47:38
问题 All of a sudden my app seems to have developed a routing error uninitialized constant DashboardController I am running Rails 3.2.0 with ActiveAdmin (0.6.0) and up until today everything seemed to be working fine. The log is reporting the following error which occuring when trying to run localhost:3000: Started GET "/" for 127.0.0.1 at 2013-04-04 18:59:21 +0100 ActionController::RoutingError (uninitialized constant DashboardController): activesupport (3.2.0) lib/active_support/inflector

Token authentication with Rails and Devise

北慕城南 提交于 2019-12-31 10:36:11
问题 I'm following this excellent article to setup the authentification part of my rails (3.2) API: http://blog.joshsoftware.com/2011/12/23/designing-rails-api-using-rabl-and-devise/ I have done the following step: -Added devise to Gemfile -Enabled devise for the user model and ran the migrations required -My user model is class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable devise :token_authenticatable attr

Rails 3, RSpec 2.5: Using should_receive or stub_chain with named scopes

隐身守侯 提交于 2019-12-31 10:32:21
问题 I use Rails 3.0.4 and RSpec 2.5. In my controllers I use named scopes heavily, for example @collection = GuestbookEntry.nonreplies.bydate.inclusive.paginate( :page => params[:page], :conditions => { ... }) In my tests, I want to be able to mock the result of such a query, not the wording . I do not think it makes sense to do something like GuestbookEntry.stub_chain(:nonreplies, :bydate, ...).and_return(...) because this test will fail the moment I decide to reorder the named scopes. With

How can I use Mongoid and ActiveRecord in parallel in Rails 3?

不想你离开。 提交于 2019-12-31 09:17:09
问题 I'm using rails 3, and began my application with ActiveRecord. Now, I have many models, and the relations are starting to get complicated, and some could be more simply expressed with a Document-Oriented structure, so I'd like to try migrating to MongoDB and use Mongoid. I've always heard that you didn't have to eitheer use all MongoDB or nothing, but that you could use the two in parallel while migrating. I don't see how to go about this from the docs though. For example, I have: class User

difference between resource and controller generators

▼魔方 西西 提交于 2019-12-31 09:03:39
问题 when I do rails g model user name:string rails g controller users index create new destroy show and edit config/routes.rb to add: resource :users bundle exec rake routes gives: users POST /users(.:format) {:action=>"create", :controller=>"users"} new_users GET /users/new(.:format) {:action=>"new", :controller=>"users"} edit_users GET /users/edit(.:format) {:action=>"edit", :controller=>"users"} GET /users(.:format) {:action=>"show", :controller=>"users"} PUT /users(.:format) {:action=>"update