ruby-on-rails

Rails MySQL query time confusion

Hi, I have a count calculation query which I am running thousands of times in my Rails app, once for each customer in the db. When I run the query in my MySQL client with query cache disabled the query takes last than 1ms. However, when I run my task from the Rails console with query output enabled I've noticed that after the first ...

Connecting from sqlite database in rails

hi , iam facing problem with connecting with the Sqlite database,instead of mysql,. is anyone please tell me the procedure to connect with the sqlite database from rails. Thanks in advance. Anu. ...

Configure mail.rb for localhost testing

hi...is it possible to configure mail.rb (in RESTFUL authentication) to test email activation locally? the default file is ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => "mail.example-domain.com", :port => 25, :domain => "www.example-domain.com", :authentication => :login, ...

jQuery design question

I have a rails app, where I have 2 models, user and notice. A user has a single notice. I'm using jQuery to implement the 'edit' and 'update' methods for notice. In order to send the correct 'id' of the notice to my notice controller i've created a div tag in the view with the id of the notice, so that i can get the id of the notice u...

deploying rails app to production environment

I've been playing around with a rails app and showing the customer the updates by deploying it on heroku. Now the customer wants it set up on their on server...as a live site. Heroku made deploying rails app so simple that I can not wrap my head around starting from scratch on a server. To the experienced rails developers, what all is...

Accelerate S3 upload with paperclip

I'm using paperclip for uploading images in S3. But I've noted that this upload is very slow. I think because before complete the submit the file has to pass by my server, be processed and be sent to the S3 server. Is there a method for accelerate this? thanks ...

named_scope dependent on existence of association is breaking tests

User model: class User < ActiveRecord::Base named_scope :clients, :conditions => "roles_users.role_id = #{Role.find_by_name('client').id}" end When testing, throws error: Called id for nil, which would mistakenly be 4 -- if you really wanted (etc.) Role fixtures: client: name: client user: name: user Apparent problem:...

[Rails] Is it possible to validate on custom method?

I'm trying to use some validation only if a specific method in my controller is being called: validates_presence_of :reasons, :on => :update_description However I get this error: TypeError in RegistrationsController#create nil is not a symbol /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:586:in `s...

Rails' page caching vs. HTTP reverse proxy caches

I've been catching up with the Scaling Rails screencasts. In episode 11 which covers advanced HTTP caching (using reverse proxy caches such as Varnish and Squid etc.), they recommend only considering using a reverse proxy cache once you've already exhausted the possibilities of page, action and fragment caching within your Rails applicat...

reverse page numbers with will_paginate

Is there any simple way to reverse page numeration with will_paginate? I want for the top page (last time-wise) to be #1, and the last (earliest) to be #N. The reason for that is page contents shouldn't change with time, which is good for SEO. ...

Rails Eager Loading Question Find(:all, :include => [:model])

Hello, I have a Topic and a Project model. I have a Many-to-many ass between them (HABTM one). In the Topic's Index Page, I want to display the number of projects that each topic have. So I have @topics = Topic.all(:include => [:projects]) In my controller, and so far so good. The problem is that the Project Model is so big that the ...

Ruby on Rails: Finding all topics in a certain category?

I'm trying to find all topics in a one particular category, but I'm not sure if this is the most efficient way to do it: Topic.all.select { |topic| topic.categories.include?(category) } The above works for me but it seems that it takes MySQL a long time to find the records. Is there anything more efficient? ...

Creating a record and adding associated records to it

I have a following model class Order < ActiveRecord::Base has_many :products, :through => :line_items end class Product < ActiveRecord::Base belongs_to :order end line_items is a table, that associates an Order with multiple products. create_table "line_items", :force => true do |t| t.integer "order_id" t.integer "p...

What are the advantages and the pitfalls of specialized rails hosting services?

Hope my question does not pose as too wide. So I try to frame my question not to get too similar answers to the question of this question. Currently I have deploy my rails application on Linode. The service works fine, the price is reasonable. But there are those administering works time to time. I could live without those. Recently I s...

rails: How do I convert a symbol to a class

Given a symbol in rails, how do I get a Class? So I could call something like: give_class(:post).find(:all) or similar. ...

uninitialized constant ActionController when running rake db:migrate

Let me preface this by saying I'm a total rails noob. I've just written a migration but when I try to run rake db:migrate --trace I get this error. (in /home/dkerschner/hsp-agent) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! uninitialized constant ActionController /var/lib/g...

How do I include an instance method inside a before_save callback in a plugin?

Hi there, I'm creating a plugin and am having a hard time defining a before_save filter that calls an instance method I've just defined. Here's a quick sample: module ValidatesAndFormatsPhones def self.included(base) base.send :extend, ClassMethods end module ClassMethods def validates_and_formats_phones(field_names = [...

Restful routing with different controllers for the same resource resolving the "wrong" url

I have a Store model. And two controllers: stores_controller admin/stores_controller now in the list view of the admin/stores_controller I am trying to generate a link to the destroy action in the admin/stores_controller but every variation I have tried either goes to the stores_controller (so not the admin one) or to some other inco...

If given Model.find(:all), how to get the name of the Model/Class from the given result?

m = Model.find(1); m.class_name would give you "Model" If we have: m = Model.find(:all); How do we get the name of the model from m alone? ...

Rails - HABTM relationship...Storing Checkbox Values from Users

Hi..Im trying to figure out this HABTM relationship issue to store in the interests of users within my database. The interests table has a list of different interests with id and name (i.e: id=1 , name = 'Music') I have a users model => user.rb has_and_belongs_to_many :interests and an interests model => interest.rb has_and_belongs...