ruby-on-rails

Users take sessions of other users when sessions are stored in memcached (Rails)

Hello experts, I have a very weird problem, when storing my session in Memcached. From time to time some users takes the session of others. E.g. John, becomes logged in as Maria, Maria as Chris and so on. I use Rails 2.3.4, but the same problem has been happening with earlier versions of Rails. I use only one Memcache server and it's r...

rails - :joins sanitizing/substitution

is it possible to specify parameters for :joins similar way as for :conditions? here is an example (sql code is irrelevant) named_scope :threads, { :joins => [" LEFT JOIN groups_messages gm ON messages.id=gm.message_id AND gm.group_id IN (?) ",@group_ids_array], :conditions => ["creator_id=? AND messages.id IN (?)", current_user_i...

Calculated field in RoR (act as an ActiveRecord method)

I am building an app for cognitive tests in Rails. I have a number of tests (Quiz objects) for my visitors. In the home page I want to show only quizzes that are ready for consumption: they must have a number of questions and a number of possible answers. Of course I could query with SQL, or create a class method retrying all objects whe...

How to get the list of attributes of a activerecord model that can be mass-assigned

I would like to have a list of all attribute names that can be mass assigned. I need this for a custom form builder that will not add input fields by default that cannot be mass assigned. For example if I have a model like : class Post < ActiveRecord::Base attr_protected :account belongs_to :author validates_presence_of :title, ...

Can I specify a different recipient for an ActionMailer email based on the environment?

I'm wondering if it's possible to configure a Rails email derived from ActionMailer to send to a different recipient based on the environment. For example, for development I'd like it to send mail to my personal email so I don't clog up our company email account with "Testing" emails; for production however I want it to use the real add...

Phusion-Passenger seems to create MANY (140+) orphaned processes.

Hi there, We're running 3 Apache Passenger servers sharing the same file system, each running 11 Rails applications. We've set PassengerPoolIdleTime = 0 to ensure none of the applications ever die out completely, and PassengerMaxPoolSize = 20 to ensure we have enough processes to run all the applications. The problem is that whe...

Ruby on Rails: "find_create_by_user"

Hello, I'm wondering why this is not working for me: Recipe.find_or_create_by_user_id(current_user.id, :name => "My first recipe") That creates the recipe fine if one does not exist by the user's id, but the name ("My first recipe") isn't included into the newly created entry. Is there something I'm doing wrong? I can't quite figure ...

Is it possible to have Haml indent HTML generated by a view helper in Rails?

Say I have a things resource with a view helper method such as: module ThingsHelper def foo ret = "" 3.times { ret += content_tag(:li, "foo") } content_tag(:ul, ret) end end This, then, is used in a template: %p = foo The HTML source that's generated looks like this: <!DOCTYPE html> <html> <head> <tit...

Is 37 Signals business advice applicable only to those with a captivated audience already eg courtesy of Ruby On Rails?

I think that most of the advice that comes from 37 Signals is fascinating. I ask this question as i can't help also thinking that the some of the principals will only pull in customers if you have a fan base to call on such as the Ruby On Rails evangilists? ...

Is there a way to filter unsupported formats in the routes file?

I have a Rails app that's getting hit by ScanAlert calling /login.php, but the app is throwing a 500. I'd like to filter any format that's not supported by my site, and 404 instead. My original inclination was to create a before_filter in application_controller.rb that removes any :format that's not :html, :xml, or :js, then render 404....

Randomly display a different background every time a page is displayed

I have 5 images which I want to use as a background at different times (randomly one needs to be chosen to be the background for the body tag). How do I go this, can this be done in the Rails Controller/method or through ERB or through JQuery? ...

rails attachment_fu public_filename problem

Hi, attachment_fu generates wrong public_filename. >> pic.thumbnails => ProductPicture id: 12331, product_id: nil, parent_id: 12330, content_type: "image/png", filename: "b_9788994035109_mid.png", thumbnail: "mid", size: 16562, width: 205, height: 205, created_at: "2009-10-05 02:43:50", updated_at: "2009-10-05 02:43:50", ProductPictu...

Rails RSpec with Multiple Databases

I run a Rails app, and we're in the process of splitting out our signup process to a separate app. The signup app has its own separate database (for CMS and collecting prospects), but it also needs to have access to the main database. This works really well using ActiveRecord::Base.establish_connection. However, I'd like to be able to ...

Rails Modal Form Validation

I am using Lightbox Gone Wild to display a modal dialog with a form inside. I am using a vanilla New view. This works like a champ up until a user doesn't input valid form data. Invalid data causes the controller to direct the user to the New view directly with the error message. Obviously, I would prefer the error be returned to the mod...

Confirm Delete on Javascript Remove Event

I'm using a javascript call to dynamically remove a field from a form. My problem is that the action happens very quickly, and it's not reversible. So I'd like to add the standard Rails delete confirmation, but I can't figure out how to make it work. Basically, I want to add this ... :confirm => ‘Are you sure?’ Here's the line of j...

How do rails association methods work?

How do rails association methods work? Lets consider this example class User < ActiveRecord::Base has_many :articles end class Article < ActiveRecord::Base belongs_to :user end Now I can do something like @user = User.find(:first) @user.articles This fetches me articles belonging to that user. So far so good. Now further I ...

When to stop DRYing up the code?

So DRYing up code is supposed to be good thing right? There was a situation in one of the projects I was working on where there were certain models/entities that were more-or-less the same except the context in which they were being used. That is, Every such entity had a title, descriptions, tags, a user_id etc and some other attributes....

Making files uploaded to s3 public

I'm using s3-swf-upload-plugin in a Rails project to upload directly to S3. Pretty nifty, but can't seem to figure out how to make the uploaded files public. S3 doesn't seem to have the concept of public "buckets". Any ideas? ...

Rails ERB <%- ... -%> vs. <% ... %>

So for an ERB file, what's the difference between <%- ... -%> vs. <% ... %>? As far as I can tell, they serve the same purpose but one requires more typing than the other. ...

Ruby on Rails: Do you recommend using Observers?

I notice it's used primarily for sending emails. Let's say I want to send an email after every comment is created. Is using Observers really necessary when you could just place the Mailer.deliver_email(user) in your comments_controller.rb's create action instead? ...