ruby-on-rails-3.1

Rails search functionality

跟風遠走 提交于 2019-12-21 06:40:58
问题 I am taking a rails class at my University and I am trying to create a search form which will show the results on the same page rather than show a different page of results. Is this something simple to do? I am creating a museum app with artifacts for each museum but I want the user to search artifacts from either page. On my routes.rb I have resources :artifacts do collection do get 'search' end end On my museum index I have the code below that he gave us but not sure how to tweak the get

Getting my images in css to work on rails and asset pipeline with upgraded app on Heroku

送分小仙女□ 提交于 2019-12-21 06:39:09
问题 This is an app that I am upgrading to Rails 3.1, along with the asset pipeline. Everything looks peachy in development, but when I push to heroku, the images in my css are not displaying. Couple of questions. First, should I leave these files with the css extention, or should they be renamed to either scss, or css.scss.erb? The other question I have is how should I reference images in the css. Currently I have... background: #B4F4FF url(/assets/img01.jpg) repeat-x left top;^M I am pretty sure

how can i insert data into table by the help of migration and that table is generated previously through another migration

ぐ巨炮叔叔 提交于 2019-12-21 06:16:14
问题 I have a role table with user name and role and company. I want to insert data into that table through a new migration file so how can i do this? I got a code like this but how can i use it and where i am not able to understand. class Foo < ActiveRecord::Migration def self.up Users.new(:username => "Hello", :role => "Admin") end def self.down Users.delete_all(:username => "Hello") end end 回答1: This: Users.new(:username => "Hello", :role => "Admin") does not insert data into your table. It

Devise - login from two model

家住魔仙堡 提交于 2019-12-21 05:39:18
问题 I have two user models, first is from remote database as legacy and for internal company purposes. (Employee logins). Second is our project for public registration and sign in but I want one login form. I have searching long time, but some solutions are confusing for me. First legacy looks like (only for reading and authentication): class CrmUser < ActiveRecord::Base require Rails.root.join('lib', 'devise', 'encryptors', 'sha1') # Include default devise modules. Others available are: # :token

Unable to get Rails 3.1, Compass, Sass, Blueprint working on Heroku Cedar

空扰寡人 提交于 2019-12-21 05:13:10
问题 For the most part I've followed the direction laid out here Which is resulted in the following error coming from the initializer it asked me to create: from /app/config/initializers/sass.rb:1:in `<top (required)>' 2011-09-05T16:45:42+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/railties- 3.1.0/lib/rails/railtie/configuration.rb:78:in `method_missing': undefined method `sass' for # <Rails::Application::Configuration:0x00000003845528> (NoMethodError) The Heroku page on getting started

Mocking file uploads in Rails 3.1 controller tests

爷,独闯天下 提交于 2019-12-21 04:12:32
问题 My controller accesses the tempfile attribute of an uploaded file and passes it to another mocked component. My test code has @file = mock(Object) @file.stub_chain(:tempfile, :path).and_return('thefile.zip') # ... post :create, :file => @file and the controller code calls params[:file].tempfile.path . After upgrading from Rails 3.0 to 3.1, the above line started failing with undefined method `tempfile' for "#[RSpec::Mocks::Mock:0x2b0d9a0 @name=Object]":String That is, Rails 3.1 converted

How do I add Devise's 'timeoutable' module to an existing Devise install? - Rails 3.1

假如想象 提交于 2019-12-21 03:27:20
问题 These are the instructions to add a module to an existing Devise install: https://github.com/plataformatec/devise/wiki/How-To:-change-an-already-existing-table-to-add-devise-required-columns But I can't seem to locate the necessary columns for timeoutable . I looked for the fields that timeoutable requires in the Devise library: https://github.com/plataformatec/devise/blob/master/lib/devise/schema.rb - but there is no such method in that schema file. The model just has a custom method with no

How to create a new DateTime object in a specific time zone (preferably the default time zone of my app, not UTC)?

ⅰ亾dé卋堺 提交于 2019-12-21 03:09:09
问题 I have set the time zone in /config/application.rb , and I expect all times generated in my app to be in this time zone by default, yet when I create a new DateTime object (using .new ), it creates it in GMT . How can I get it to be in my app's time zone? /config/application.rb config.time_zone = 'Pacific Time (US & Canada)' irb irb> DateTime.now => Wed, 11 Jul 2012 19:04:56 -0700 irb> mydate = DateTime.new(2012, 07, 11, 20, 10, 0) => Wed, 11 Jul 2012 20:10:00 +0000 # GMT, but I want PDT

Couldn't find User with id=1

荒凉一梦 提交于 2019-12-21 02:36:24
问题 I've a current_user method to handle authentication. application_controller.rb protect_from_forgery helper_method :current_user def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end but when I try to acces a to a page I get the following error: Couldn't find User with id=1 app/controllers/application_controller.rb:10:in `current_user' How can I pass @current_user a sort of default value so if there's no user it will redirect to login page. Thanks for helping

multiple database connections with has_many through

人走茶凉 提交于 2019-12-21 01:44:10
问题 How can I make a has_many through work with multiple database connections? I have a database named "master" that holds the location information. That is updated from a separate application. Users can have access to many locations, but all the other models are located in another database named "budget". Here are how the models are setup. # place.rb class Place < ActiveRecord::Base belongs_to :user belongs_to :location end # user.rb class User < ActiveRecord::Base has_many :locations, :through