ruby-on-rails-3.1

stringify_keys error after supplementing session variables in functional tests

天涯浪子 提交于 2019-12-07 16:33:36
I'm in the process of upgrading to Rails 3.1.0 from 3.0.10, and I'm using Devise for authentication. I have a number of functional tests that require me to set a single session variable. Stuff along the lines of: test "new clears current_lesson_id from session" do get :new, nil, {'current_lesson_id' => '234234'} assert_response :success assert_nil session[:current_lesson_id] end This was failing as my session info was clobbering the devise authentication session data, so my previous solution was to merge with the default session: test "new clears current_lesson_id from session" do get :new,

Michael Hartl's Ruby on Rails Tutorial. Failed test in Chapter 9

夙愿已清 提交于 2019-12-07 15:24:34
问题 I'm a newbie working through Michael Hartl's Tuby on Rails Tutorial and I have a couple of failed items in a test in Chapter 9. Running RSPEC test returns: sis-macbook-pro:sample_app Lagaspi$ bundle exec rspec spec/ ...................................FF................................ Failures: 1) Authentication authorization in the Users controller visiting the edit page Failure/Error: before { visit edit_user_path(user) } NameError: undefined local variable or method `user' for #<RSpec:

Undelete acts_as_paranoid deleted user on devise sign in

老子叫甜甜 提交于 2019-12-07 15:17:06
问题 I have a Rails 3.1.3 app which uses devise for users authentication and soft-deletes them with acts_as_paranoid . I want the accounts to be undeleted upon password recreation, user sign up and user sign in, so if they provide a deleted email, I grab that account, make it live again, and then continue with the action (password recreation, or sign in). But in the Users::SessionsController#create action, after undeletion of the user it gets an Unauthorized error (but the user should now be

rails 3.1 inflection problem

别来无恙 提交于 2019-12-07 13:11:30
问题 I have a Rails 3.1 app with the following 2 models class Listing < ActiveRecord::Base has_many :listing_saves end class Team < ActiveRecord::Base has_many :listing_saves has_many :saved_listings, through: :listing_saves, source: 'listing' end The Join model looks like this class ListingSave < ActiveRecord::Base belongs_to :team belongs_to :listing end Mow I think that there is an inflection problem because whenever I try to run my tests I get the following error (this is an example of an

Using passenger to run both Rails 3.0 and Rails 3.1 app (using different rvm gemsets)

纵饮孤独 提交于 2019-12-07 11:49:44
问题 I just followed these directions for installing a new rvm gemset and installing rails-3.1.0.rc2 on my local machine. At first I was getting a Passenger error saying the rake-0.9.2 gem could not be loaded, but I found this reminding me to run "$ passenger-install-apache2-module". It installed fine prompted me to add the following to my Apache config file (/etc/apache2/httpd.conf): LoadModule passenger_module /Users/robs/.rvm/gems/ruby-1.9.2-p180@rails-3.1/gems/passenger-3.0.7/ext/apache2/mod

Rails 3.1 distinct find and missing attributes

风流意气都作罢 提交于 2019-12-07 09:16:18
问题 class State < ActiveRecord::Base has_many :cities end class City < ActiveRecord::Base belongs_to :state has_many :companies end class Company < ActiveRecord::Base belongs_to :city end I'm trying to list all states, and their respective cities, that contain at least one company registered. My first try was the following query: states = State.joins(:cities => :companies).includes(:cities) Which works, but I end up getting duplicates if a state has more than one city with companies in it. I then

Rails form issuing GET request instead of POST request

馋奶兔 提交于 2019-12-07 06:45:55
问题 I am making a Rails 3.1 app and have a signup form that was working fine, but I seemed to have changed something to break it.. I'm using Twitter bootstrap and twitter_bootstrap_form_for gem. I made some change that messed with the formatting of the form fields, but more importantly, when I submit the Sign Up form to create a new User, the information is showing up in the URL and looks like this: EDIT: This is happening in the latest versions of Chrome and Firefox http://localhost:3000/?utf8=

Access Asset Path from Rails Controller

一笑奈何 提交于 2019-12-07 06:22:34
问题 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? 回答1: ActionController::Base

Eager loading association but limit return

此生再无相见时 提交于 2019-12-07 05:52:11
问题 It seems like a simple query but I just can't nail it. Basically it boils down to the age old concept of a categories having posts. The expected associations are in place, a category has_many posts whilst a post belongs to a category. I want to retrieve all the categories with their posts but limit the number of posts to 10. Any ideas? 回答1: This isn't something that you can do with raw SQL as LIMIT's are on the total dataset size, not anything else. The only way of doing this purely by SQL is

Devise + Active Admin Redirect

有些话、适合烂在心里 提交于 2019-12-07 04:16:57
问题 I am having trouble setting up the redirect for my application. Users should go to their profile (users/show) and admins should go to the admin dashboard.. How do i set this up? Currently getting the following error: NameError in ActiveAdmin::Devise::SessionsController#create undefined local variable or method `admin' for #<ActiveAdmin::Devise::SessionsController:0x007febe12667e8> Application controller def after_sign_in_path_for(resource_or_scope) if admin redirect_to admin_dashboard_path