ruby-on-rails

foo_url(mock_foo) sometimes doesn't work in rspec tests

I am trying to write an rspec test for a controller that accesses a model Group. @request.env['HTTP_REFERER'] = group_url(@mock_group) ### Line 49 I get this: NoMethodError in 'ActsController responding to create should redirect to :back' You have a nil object when you didn't expect it! The error occurred while evaluating nil.rewr...

When do you use <% -%> instead of <% %>

I've noticed that in some lines of rails views, this is used: <% # Code... -%> instead of: <% # Code... %> What is the difference? ...

In Rails, with cookie-based session store, are session and cookies the same thing

I've always been using the cookie-based session store, and never even knew about Cookies until now. So is there any situation where I'd need the cookies hash? ...

Ruby on Rails 2.1 Subdomain-Cookie issues

When using a subdomain and trying to view anything related to current_user. user is sent to a new session page, the page shows the session is created and gives the option to logout. I can use no subdomain and it works fine. ...

How can I put (parts of) a large object graph in Rails.cache?

I have a class in which looking up an instance is expensive, so instances are cached: class Foo def self.find(id) Rails.cache.fetch("Foo.#{id}") do // some expensive lookup, like an HTTParty request, or a long SQL query ... end end end That works fine until Foos have related Foos: class Foo def children ...

Best way to stress test a rails web app?

Are there any good (preferably free) tools out there? Can they give accurate estimates that reflect production results when the app goes live? ...

Starting out doing server side things - what languages and techniques to choose?

I've been doing html, css and javascript for quite a long time, mostly for my very own enjoyment. I would say I know fairly much, I've created many simple games and apps and experiments with javascript. However there is only so much that is possible to do in the browser, for any more "complete" websites I am constantly confronted with my...

Routing without namespace in Rails (2.2)

Related to the question asked here -- http://stackoverflow.com/questions/182040/default-segment-name-in-rails-resources-routing. Having trouble in edge rails trying to generate resources without a namespace prefix (i.e. /:apple_id/oranges/). Using the plugin gives me //:apple_id/oranges? Any easier way to do this? Maybe a 2.2 issue? ...

How can I define a BigInt primary key with Rails 2.1 and MySQL?

Since Rails 2.1, if you define a new column in a migration with the type set to :integer and the :limit set to 5 or more, the column actually created in your MySQL database will be of type BigInt. That's perfect. But I cannot figure out how to create a table with a BigInt primary key. Any clues? ...

Migrate from rails 2.1.1 to 2.2.2

I am working on a project using rails 2.1.1. With the new release of 2.2.2 I want to migrate to the new version. Is there anything I need to change to migrate my 2.1.1 controllers, views, and models? ...

Scaffold Generator problem in Rails 2.1+

I have fresh Rails 2.2 install, thing is that everything work fine until I use scaffold generator. $ script/generate scaffold pages \ title:string description:string content:text $ rake db:migrate But when I launch server with this address: http://localhost:3000/pages/ I get this: NoMethodError in PagesController#index undefined m...

Custom Rails authentication / authorization

I know questions of this kind have been asked before, but my situation differs a little. On my rails app I have to validate the user login against an existing repository and then control authorization to given modules. So, I don't want the solution I go for to generate a model for my users and rely on that. The authetication per se need...

In Ruby on Rails how can I combine multiple Javascript files at runtime?

I am building a Facebook App which is heavy on Javascript. For this I have multiple Javascript files. Since in Facebook development, the page is served over a tunnel, there is excessive latency added while requesting multiple javascript files. Is it possible to combine the contents of multiple javascript files at runtime? Having multiple...

Testing Authenticity Token in Rails

Hi, I'm trying to test a method I have in my application, but I don't know how to unit test a method that is being protected from forgery, take a look at this: def index @alumnos = Alumno.paginate :per_page => 20, :page => params[:page], :order => :nombre respond_to do |format| format.html # index.html.erb ...

What's the cleanest way to override ActiveRecord's find for both models and collections?

I have library code that overrides Ar's find method. I also include the module for all Association classes so both MyModel.find and @parent.my_models.find work and apply the correct scope. I based my code off of will_paginate's: a = ActiveRecord::Associations returning([ a::AssociationCollection ]) { |classes| # detect http://dev.rub...

Rails Background task overhead

Has anybody done a comparison of the overhead of the various background processing techniques? Background/RB, Starling, Workling MemcacheQ Beanstalk Background Job (Bj) delayed_job (Dj) I will be implementing one of them on a slice and would like to know how much memory they take up so I can factor it into my decision making. ...

Rails or clone on Windows Server 2008 - Most Performant?

I am very interested in learning a Ruby on Rails / Django type web technology but am currently using Windows Server 2008 (for .Net web applications.) I have read that RoR is not very performant on Windows. Would it be unadvisable to create run a beta web application in RoR on a Windows Web server as far as performance is concerned? Wou...

RT parallel processing in Rails

I'm developing a sort of personalized search engine in Ruby on Rails, and I'm currently trying to find best way of sorting results depending on user's record, in real time. Example: items that are searched for can have tags (separate entities with ids), for example item has tags=[1, 5, 10, 23, 45]. User, on the other hand, may have fla...

Rails: Is there an equivalent to save_without_validation which skips after_save filters?

I have an after_save filter which I dont want to trigger in a specific instance. Is there a way to do this similar to save_without_validation? Thanks, ...

how to avoid duplicates in a has_many :through relationship?

Hey guys, how can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow me to have an N:M relationship between them: class Blog < ActiveRecord::Base has_many :blogs_readers, :dependent => :destroy has_many :readers, :through => :blogs_readers end class Reader < ActiveRecord::Base has_many :...