ruby-on-rails

Test if Has One Relationship has Changed in Rails

Is it possible to have a 'before_save' callback that detects if a 'has_one' relationship has changed (the relationship not the model at the end of the relationship)? For example, something that would act like this: @person.picture = @picture @person.picture_changed? # true @person.save @person.picture_changed? # false ...

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...

Formtastic Confused on Has One Relationships

I'm a bit stuck on a 'has_one' and 'belongs_to' relationship and getting it to properly display in Formtastic. I have a person model that has one picture (a profile picture). I want the user to be able to select the picture using radio buttons. So far, I have: <% form.inputs do %> <%= form.input :picture, :as => :radio, :collection =>...

Can someone please explain this line of code from a tutorial on how to reset a password with Authlogic?

I'm doing this tutorial on how to reset a forgotten password. It all works, except there's just an empty line in the email where the URL is supposed to be that will take you to the page to reset the password. The line where it should be added doesn't really make sense to me. I can't work out what edit_password_reset_url(user.perishable_t...

Is there any good intellisense tool for coding Ruby?

Hello guys On Linux environment, is there any good intellisense tool, like an IDE you use for coding Ruby on Rails? And what about Windows environment, any really good smart editor? thank you ...

Autoload path and STI inheritance

I have two models User and Manager. I use STI to inherit Manager from User model. app/models/user.rb class User < ActiveRecord::Base end custom_lib/models/manager.rb class Manager < User end I have added the custom models to load path as follows: config/environment.rb config.autoload_path += File.join(RAILS_ROOT, "custom_lib",...

How do I use YAML in ruby/rails?

I have a list of accounts I want to save as a YAML file and load it into ruby. Something like this: Account1 John Smith jsmith [email protected] Account2 John Doe jdoe [email protected] Then I want to get the email address of the person with the name of "John Doe" (for example). How do I do this? ...

In Ruby / Rails, what if a gem Foo depends on Bar 1.2.2, and cannot be Bar 2.0, but Wala depends on Bar 2.0?

In other words, can't the versions have conflicts and is there a way to solve it? Such as Foo depends on Bar and Foo doesn't support Bar 2.0, but Wala need to have at least Bar 2.0, so can Rubygems or Bundler or any mechanism handle it? ...

RackEnv/RailsEnv development not working

I am using Passenger3 with Apache2, Rails 2.3.8 with Bundler1.0.3 I can't trigger development mode from the vhost. I need to explicitly set it in ENV['RAILS_ENV'] = 'development' RackEnv development RailsEnv development Neither of these are working, it is defaulting to production. I have another 2.3.8 project that is fine with Rail...

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! ...

Any API to search Google Cache?

I am trying to search within Google Cache, so I need to fire this query: http://webcache.googleusercontent.com/search?q=cache:news.ycombinator.com/news+hacker+news And get some content like timestamp from the page. But when I do this using curl (ruby), it gives a permission denied error, i.e. scraping is blocked and that was expected...

Rails Functional Test - excluding method from setup

This should be simple but I can't find any examples. I have standard functional tests in my rails 3 application (descending from ActionController::TestCase) that look like: test "see if 1+1=2" do .... end and at the top I have a setup method: setup do ...... end How do I exclude a method? I.e. setup :except => "see if 1+1=2" do...

How do I make a table with dynamic models editable-in-place in Rails?

This is the view of a table that I have: <% @campaign_events.each do |campaign_event| %> <% model_name = campaign_event.class.name.tableize.singularize %> <tr class="<%= cycle('oddrow','evenrow') %>"> <td><%= link_to campaign_event.title, send("#{model_name}_path", campaign_event) %></td> <td><span class='model_name'><...

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],...

AWS::S3::MissingAccessKey in Paperclip but I've defined both.

I'm on Heroku, and this is a portfolio thing which I'm putting up on github for potential employers to look at, so obviously I don't want to stick my keys in a S3.yml file. I've exported S3_KEY and S3_SECRET to my environment both on Heroku and my machine and ruby can access them. But when I try and upload, it gives me the following erro...

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...

Ruby on Rails -- new install on windows 7 but cant run ruby commands, problem with path?

I just installed ruby on rails on my new computer ( I was using instantrails before) and I'm trying to get everything setup. Im running Windows 7. So I followed the instructions from this tutorial. http://blogupstairs.com/ruby-on-rails/installing-ruby-on-rails-on-windows-7/ The problem i'm guessing is step 3 "Add the newly installed ...