ruby-on-rails

Going into any Rails project folder, is there a reliable way to tell which version of Rails it is using and created with??

that is, to tell the current Rails version it should use, and also to find out what version of Rails started this project. ...

How can I write this more "ruby-ish"?

Hi folks I got the following snippet Class Artist < ActiveRecord attr_accessible :solo #boolean def change_solo! if self.solo == false self.solo = true else self.solo = false end self.save end end Is there a better way to write that? Thanks in advance cheers tabaluga ...

Stress-testing using Cucumber

I'm currently writing integration tests for a RoR REST API using cucumber. I'd also like to stress-test the API and was wondering how I might be able to re-use my cucumber scenarios to do this. I've used JMeter and httperf before for stress-tests, and of course with both tools had to write or record the tests that I wanted to include...

Validation in Rails PaperClip Plugin

I am using PaperClip in one of my Rails applications. I notice that validation works as expected, but the label of the rendered file attachment does not get red. I checked the rendered HTML and the class required to make the label red does not go there. Here is my code: <div class="field"> <%= f.label :photo %> <br/> <%= f.file_f...

In Rails 3: How do I render with layout in respond_with using a custom format?

My problem is similar to the one in this question, but the opposite. http://stackoverflow.com/questions/3876891/how-do-i-specify-layout-false-in-rails-respond-with The controller is sort of a file converter. It responds to many formats. One format is supposed to render an html layout showing metadata. This format need the layout to be r...

Test the render method in a controller with RSpec

I am trying to test the render method in a controller with RSpec (2.x). Here the code in my controller: respond_to do |format| format.html # index.html.erb format.json { render :json => @entities, :include => :properties, :overview => options[:overview] } end And here the test I try in my spec file: controller.should_receive(:r...

How can I render a template outside of a controller in Rails 3?

Hi All, I can't seem to render a template outside of a controller in my Rails 3 application. The googling I've done has been helpful, and I eventually found some useful info at http://www.swombat.com/rails-rendering-templates-outside-of-a-contro. However, this seems to be broken in Rails 3. Does anyone have any ideas how I can fix this m...

Using calendar_date_select with Rails 3

I've been trying to create a user date-of-birth selection field during sign up. The code looks like this: <div id="content"> <h3>Register</h3> <%= form_for(@user) do |f| %> <div style="width: 374px; margin: 0 auto;"> <%= f.label :name %> <%= f.text_field :name %> <div style="clear: both;"></div> <%= f.lab...

RSpec : want to have many tests for one shot method, including fixtures

Hello, I'm working on a Rails app. I want to test with rspec my method "start!" of my model Backup. So here the specs (all are methods, too): Backup should copy files to folder /backups Backup should check md5 sum Backup should delete original files For my tests, I create fake files, based on fixtures : MyFile.all.each{|r| system(...

'invalid label' error when returning JSON form rails controller when Firebug is closed

If I have Firebug console open, and return the following in a rails controller in response to an ajax call: format.json { render :json => Appointment.find_by_id(1) } I get an 'invalid label' error. But it works fine it Firebug is closed. Any ideas??? ...

With RoR, what's the best place/layer to put your memcache login in?

With RoR, you have your model, controller and view. The model has both class properties etc., and db access code mingled in. In your controllers, you use your models to fetch certain data to push to your views. In the Java world, you would have a DAO per entity, and then a 'Service' layer where you could decide to pull the object from...

rails delayed_job memory consumption problem

Hi, We're having huge problems with the delayed_job plugin - http://github.com/collectiveidea/delayed_job/ When we start tasks with "ruby script/delayed_job start", the process never lets go of RAM it acquires. So it starts with 10%, 25%, gets to 80% and never lets go of the ram, even if it has no jobs to process. Any ideas how we ca...

Authlogic + Rails3 - undefined method `Login' for nil:NilClass

Im new to Rails, and decided to start of with Rails3. After a lot of searching ive managed to get a little bit of Authlogic working. I'm able to register a user, login & logout. Now, I would like to add more features, get more of authlogic working. I'm using Railscast EP 160 as my reference. Portions of the code found on the tutorial t...

Can ASP.NET MVC return a javascript response like Ruby on Rails can?

Hello. I'm diving into ASP.NET MVC and I'm coming from a Ruby on Rails background. I'm trying to understand how ASP MVC handles AJAX functionality and, after reading some of the tutorials on the ASP website, it appears they implement AJAX functionality very differently. One of the ways that RoR handles AJAX functionality is by returni...

In Rails, what are some good View-specific design patterns that make handling many states easier?

The anti-pattern that I want to kill is: - if !current_user # do something - if !member # do something else - if admin # blah blah blah - else # Bored now. I suspect the answer has something to do with view helpers and partials, but I'm wondering what some of the best practices and design patterns are. Thanks! ...

counter_cache in single table inheritance

I am wondering if the counter_cache would work in single table inheritance. For these models: class User has_many :questions end class Question belongs_to :user, :counter_cache => true end class SimpleQuestion < Question end class ComplexQuestion < Question end So will the following counters work? create_table(:users) do |t| ...

Rails/Postgresql: getting "password authentication failed for user postgres" error on production server

Rails 3.0.1/Ruby 1.9.2 with Postgresql 8.4 work great on my home machine, however I'm getting this error on a Ubuntu server. I'm sure that the password I upplied in the database.yml file is correct, because when I log in as "postgres", it lets me in: sudo -u postgres psql template1 Password: psql (8.4.5) I have edited the "pg...

Using cucumber with staging database without truncation and transactions

We have a Ruby on Rails 2.3.8 project, where data are almost exclusively read only. We would like to write acceptance tests which use staging database (copy of the production database) So we do not want to use transactions or truncation of the database tables before or after features and scenarios. Is it possible? ...

Managing restful resources in Rails 3

I am trying to convert my Rails 2 app to Rails 3, but I can't delete any resources using my old Rails 2 code. To be precise I am trying to delete a resource, using this link: <%= link_to image_tag("misc/delete.png"), @book, :confirm => 'Are you sure?', :method => :delete %> And yet it doesn't work at all! It just behaves as if the :co...

rails asynchronous communication and xhr polling

I need to write a Rails application (JRuby) that does asynchronous communication with another service in the background. There needs to be one connection per browser session. (It does not really need to be a open TCP connection but I need to free resources after the session ends.) The communication with the background service is not stri...