ruby-on-rails-3

Capistrano still trying to connect to my old repo

亡梦爱人 提交于 2020-01-05 04:36:09
问题 I have changed my repo to Github.com from Cadaset.com and changed the repository setting in my deploy.rb file to my new Github repo. When I run cap deploy it still tries to connect to my old repo on Codaset.com. I cant find any reference to my old repo so cant see why it is doing this. I have tried cap deploy:setup that works but then I get the same error on cap deploy 回答1: You have to delete the shared copy on your server stored at PATH_TO_APP/shared/cached-copy . Remove the cached-copy

mongodb function from rails

杀马特。学长 韩版系。学妹 提交于 2020-01-05 04:33:11
问题 I use mongomapper with mongodb for rails models. In the mongodb I have this function db.system.js.save({_id:'resumenTemporada',value:function(collection, condition){ var res= db[collection].group({ key:{}, reduce:function(obj,prev){ prev.ppa += obj.precipitation; if( obj.temperature < 5 && obj.temperature >0) prev.hf += obj.temperature/4; }, initial : {ppa:0,hf:0}, cond: condition}); return res ; } }); And get this output > db.eval("return resumenTemporada('stations',{nombre:'pua',fecha:{$gt:

How to chain or combine scopes with subqueries or find_by_sql

ⅰ亾dé卋堺 提交于 2020-01-05 04:20:12
问题 I would like to perform a query like SELECT * FROM ( SELECT * FROM products ORDER BY price ASC ) AS s GROUP BY item; which return the cheapest of all products for each item. Using this subquery is good because it can run in O(N logN) time. So I can find this with find_by_sql, but it would be nice to be able to chain it with other scopes for Product. Anyone know how to either write this as a scope or chain scoped and find_by_sql? 回答1: You should be able to do something like Product.from("

How to add a User model validation to block certain email domains

我们两清 提交于 2020-01-05 04:15:10
问题 I would like to have a list of email domains that are validated against to prevent from registering on my app. 10minutemail.com, yopmail.com, mail.com, mail.ru etc... I have a list of domains in my user model like so: BAD_DOMAINS = [/10minutemail.com/, /yopmail.com/, /mail/ I would like to add a User validates on the email field to add an error if the user is registering with one of these domains. BAD_DOMAINS.each { |rule| return true if !domain.match(rule).nil? } I have that regex working,

Heroku & Rails - Varnish HTTP Cache Not Working

你离开我真会死。 提交于 2020-01-05 04:03:06
问题 My heroku website's root page is essentially static, it has some ruby code in the view when its generated, but there's nothing specific to a single user, so I'd like to have it cached by Varnish and served up without hitting my dyno (note that there are other pages that are dynamic in the application). Heroku makes it seem very simple here. Just add response.headers['Cache-Control'] = 'public, max-age=300' and it'll cache for 5 minutes before regenerating. To test this I made the changed and

Ruby on Rails 3: has_one association testing

梦想的初衷 提交于 2020-01-05 03:45:06
问题 I may have my associations messed up. I have the following models: User and UserProfiles. My models: class User < ActiveRecord::Base has_one :user_profile, :dependent => :destroy attr_accessible :email end class UserProfile < ActiveRecord::Base belongs_to :user end I have a column named "user_id" in my user_profiles table. My factory is setup like so: Factory.define :user do |user| user.email "test@test.com" end Factory.sequence :email do |n| "person-#{n}@example.com" end Factory.define :user

Ruby on Rails 3: has_one association testing

大兔子大兔子 提交于 2020-01-05 03:44:12
问题 I may have my associations messed up. I have the following models: User and UserProfiles. My models: class User < ActiveRecord::Base has_one :user_profile, :dependent => :destroy attr_accessible :email end class UserProfile < ActiveRecord::Base belongs_to :user end I have a column named "user_id" in my user_profiles table. My factory is setup like so: Factory.define :user do |user| user.email "test@test.com" end Factory.sequence :email do |n| "person-#{n}@example.com" end Factory.define :user

How can I prevent ActiveRecord from writing to the DB?

帅比萌擦擦* 提交于 2020-01-05 03:43:12
问题 I have a somewhat special use case, where I'd like to create a method that accepts a block, such that anything that happens inside that block is not written to the DB. The obvious answer is to use transactions like so: def no_db ActiveRecord::Base.transaction do yield raise ActiveRecord::Rollback end end But the trouble is that if my no_db method is used inside of another transaction block, then I'll ned up in the case of nested transactions. The drawback here is that nested transactions are

searching multiple polymorphic items using thinking sphinx

最后都变了- 提交于 2020-01-05 02:35:26
问题 I have an attachments table that has multiple values (via polymorphic assoc). I'd like to be able to search for multiple values (like an AND in SQL) via thinking-sphinx. For example: class FieldValue < ActiveRecord::Base belongs_to :customized, :polymorphic => true end class Attachment < ActiveRecord::Base has_many :field_values, :as => :customized, :dependent => :destroy define_index do has field_values.field_id, :as => :field_ids, :type => :multi indexes field_values.value, :as => :field

Where is the controller of Devise ? how to add data from other models in users/edit page?

自闭症网瘾萝莉.ら 提交于 2020-01-05 02:05:05
问题 it seems devise do not create any controller file in app/controller folder, now I am looking to show some custom info from other models in users/edit view but not able to figure out how to do it since there is no controller to add @num_of_cars = current_user.num_of_cars.all I am looking to show num_of_cars in users/edit page but not able to figure out how to do it EDIT - the below mentioned code giving me error, I am putting this code in my devise/registration/edit file <%= render partial: