ruby-on-rails3

Calling alias_method from an ActionController, NoMethodError

In Rails 3 I'm trying to call alias_method from my before_filter but I'm getting this error: NoMethodError in MyController#index class ApplicationController < ActionController::Base before_filter :my_test protect_from_forgery helper :all def my_test debugger alias_method :new_method_name, :old_method_name end en...

Rails - jquery-html5-upload ?

Hello, Has anyone been able to get the jquery-html5-upload plugin to work with Rails 3 + PaperClip + S3? Know of any tutorials? http://code.google.com/p/jquery-html5-upload/ Thanks ...

Augmenting Bates' `find_commentable` method

I'm watching a Ryan Bates screencast on polymorphic relationships, and he uses this private method for finding all comments related to a nested model. So I could find all the comments of a given Post with this : def find_commentable params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value...

Confusion about nested routes in Rails 3, specifically autogenerated paths

For each species, I have many datasets. For each dataset, I have many phenotypes. The datasets have names which, within a species, are primary keys. The species, too, have string primary keys (e.g., Hs for Homo sapiens). So, I want to be able to specify a phenotype as follows: /species/Hs/mcgary/1 where mcgary is the name (slug) of th...

If a Rails app uses "require 'gem_name'" instead of "gem 'gem_name'" or "config.gem 'gem_name'", will it be faster?

because gem 'gem_name' # Rails 3.0 or config.gem 'gem_name' # Rails 2.x will load the gem no matter what the controller is... will a require 'gem_name' in the controller source code actually make the Rails server run faster because not every controller will load that gem? ...

Rails, Getting a File's name when uploading a file to the server

Hello. I'm using an AJAX uploader in Rails 3, along with paper_clip and have files uploading here: def upload @photo = Photo.create({ :photo => params[:file], :title => params[:filename] }) respond_to do |format| format.json end end I want to set the photo's title as the photo's filename, but don't know how t...

Rails - Include a Date/Time Stamp in a string on create

Hello, in my def create controller I'd like to include something along the lines of: :description = > 'Uploaded on May 27, 2010" How can I make the May 27, 2010 dynamic in the controller? Thanks! ...

Rails, Uploading multiple Files to an Album

Alright this one's tricky - don't shy off! I've setup a multi-file uploader with Rails 3 + paperclip + Ajax Upload (http://valums.com/ajax-upload/) My controller is as follows (which works): def upload @photoalbum = PhotoAlbum.create @photo = @photoalbum.photos.create({ :photo => params[:file], :title => params[:filename],...

Obtaining a Nested Model's Count in the Controller

I have the following two models: photoalbums has_many:photos photos belongs_to:photoalbums When I show a list of all the photoalbums, I want to also say how many photos exist in the album: Controller: def index @photoalbums = PhotoAlbum.all end View: <%# Get the number of photos per this album %> <% @photos = Photo.find_b...

Rails 3 Rake Clone Database for Testing Environment

Is there a rake command in Rails 3 to clone my development database data? I noticed rake db:test:prepare and rake db:test:clone are mentioned throughout various blogs, but running them seems to do nothing. Furthermore, rake -T shows no db:test cases. I've resorted to loading a sql dump for now, but it would be great if I could just clone...

Find your way up the polymorphic tree to one parent..

I have a simple polymorphic association #comment.rb belongs_to :commentable, :polymorphic => true has_many :comments, :as => :commentable #post.rb has_many :comments, :as => :commentable accepts_nested_attributes_for :comments, :allow_destroy => true So in IRB I can do, Post.comments, or Commen...

rails 3 test case error.on(:field) Vs. errors[:field]

I am working on the Rails 3 Test cases . While writing case i got Deprecation error like DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead. Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is returned when there are no errors on the specified attribute...

Can I work with rails3 in Windows with NEtbeans IDE ?

I believe that rails 3 support for windows is not released yet. Can I use Netbeans IDE and start working with Rails 3 in windows operating system ? ...

Active Record Rails 3 associations not working properly

I have the following classes with associations: class Customer < ActiveRecord::Base has_many :orders has_many :tickets, :through => :orders has_many :technicians, :through => :ticket has_many :services, :through => :ticket end class Order < ActiveRecord::Base belongs_to :customer has_many :tickets has_many :technicians,...

Rails Active Model - scope only objects which have existing members in has_many relation

This seemed trivial at first, but I can't get it right for some time now. The relation is trivial. class Project < ActiveRecord::Base has_many :tasks end class Task < ActiveRecord::Base belongs_to :project end Now I would simply want to get all the Projects which have 1 or more tasks associated. Now to do this without any extende...

Rails and translations in liquid based themes...

I would like to return a string from a model, which can be used directly in the liquid-based template. The problem is, that I would like the string to be translated using gettext. I cannot use _("string") right into model.to_liquid, because it doesn't work. As far as I understand, the model is loaded once, and it will always return the...

Understanding Routing in Rails 3

Hi all I think I am thinking about routing all wrong. I have a very simple, two model set-up: Product and Photo. Product has_many :photos, and Photo belongs_to :product. Product has a full scaffold while Photo has a photos_controller that I am working on. In routes.rb we have: resources :products (generated by the scaffold) As phot...

List of Controller Routes in Rails 3?

Hey everybody! What I'm trying to do: I create some controllers, for example: Home About Gallery Contact Now I want to create a navigation automatically. So is there a way to programmatically fetch the list of controllers/actions to build this navigation? I don't want to fix the navigation everytime I add a controller. ...

Cucumber/Capybara test no longer run in Rails 3 project.

Do the latest versions of these gems not work with each other any more? It appears that something may have gotten out of whack in my bundle. undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:0x103e19390> (NameError) ./features/step_definitions/web_steps.rb:35 ./features/step_definitions/web_steps.rb:14:in ...

Photo Album, Photos - Paginating through an Album

Ok I need some expert advise here.... I have a Photo Album that has_many Photos... Common stuff right? Where I need expert advise is I want the use to click the desired photo album... and then see one photo at a time... Should that all be happening in the PhotoAlbum Controller? that's how I have it now but it's getting messy as I want...