ruby-on-rails

Simple syntax for testing Validation errors

I'm looking for clean and short code to test validations in Rails Unittests. Currently I do something like this test "create thing without name" do assert_raise ActiveRecord::RecordInvalid do Thing.create! :param1 => "Something", :param2 => 123 end end I guess there is a better way that also shows the validation messa...

Paper Clip failing to save attachment

Hi, I'm using Ruby 1.9 and Rails 2.3.4 with Paperclip gem to save attachments. and I followed tutorial by adding the proper migration, adding (has_attached_file :video) to the model, making the form (multipart) and adding <%= f.file_field :video %> to it... When I try to upload a file I look in the log and I see: [paperclip] Saving at...

Rails text_field default value disappear on click (and dimmed)

These text fields look great and are common on web 2.0 sites like Facebook. Basically instead of labeling the text field, you can save space by putting the label inside the text field. Typically the text is dimmed in color a bit, and when the user clicks in the text field the default value disappears, and the color switches to black or...

Rails: html_escape isn't working

Hi For some reason html escaping isn't working in my Rails application. Even if I write something like <%=h '©äö' %> it isn't converting any of the characters to HTML entities. I have no clue what the could be. It worked always fine and now just suddenly it don't. Any ideas? ...

ActiveRecord: creating a one-to-many relationship back to itself

Hi, I'm building a social networking website. I have a table of Users. Each user can have a number of other users as friends, so I have a second table Friends: user_id friend_id Based on this answer I'm trying to create the relationships. I have, class User < ActiveRecord::Base has_many :friends, :dependent => :destroy has_many :...

Tracking DB changes with Zend Framework?

I am trying to decide between the Zend Framework and Ruby On Rails for my web application. If I go with ZF, I need the following: A way to incrementally track changes to my database, as with RoR's migration feature (001_something.sql, 002_something_else.sql). A place to put SQL for the next release of my software. At work in our custo...

Password protecting a rails staging environment

I'm trying to work out what the best way to secure my staging environment would be. Currently I'm running both staging and production on the same server. The two options I can think of would be to: Use rails digest authentication I could put something like this in the application_controller.rb # Password protection for staging envir...

Rails: rake db:migrate suddenly starts at version 0 again, should start at version 16

Hi, today I just ran rake db:migrate... well, two things happened, first it reversed from version 2 to 0, so it smashed my user db (very very annoying) and now it wants to migrate vom version 1. But it should start at version 16. Any Ideas? Shema.rb is okay and right. ...

Type Error running feature in Rail's Cucumber

I'm trying to run Cucumber for my Rails application and keep getting this error: > superclass mismatch for class Point (TypeError) There's a huge stack trace from this error, but it does not point to anything specific except a missing requirement. Here's the trace: rake features (in /Users/rob/blue/blue_web) /System/Library/F...

Problem with polymorphic association in Rails

Hi, guys! I am trying to follow Ryan Bates screencast but have an error message. I did the following: 1) Create table class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.references :commentable, :polymorphic => true 2) Setup models class Comment < ActiveRecord::Base belongs_to :co...

has_many :through issue with new records

I'm modeling "featuring" based on my plan in this question and have hit a bit of a stumbling block. I'm defining a Song's primary and featured artists like this: has_many :primary_artists, :through => :performances, :source => :artist, :conditions => "performances.role = 'primary'" has_many :featured_artists, :through =...

Is there an easy way to install RMagick?

I am trying to install RMagick on my slicehost(Linux Hardy) instead of compile from source, here is what I did: $ sudo aptitude install -y imagemagick $ sudo aptitude install -y libmagick9-dev $ sudo gem install rmagick After installed, it reads GIF with no problem, however for JPEG and PNG, I keep getting this error: Magick::ImageMa...

Combine two named scopes with OR (instead of AND)

I want to find all Annotations whose bodies are either: Equal to "?" or Like "[?]" What's the best way to do this? I would like to use SearchLogic if possible, but though SearchLogic allows you to do each of the following: Annotation.body_equals('?') Annotation.body_like('[?]') and you can always chain them together: Annotation....

After adding to an array in one method, the array appears empty in another

The following is outputting an empty unordered list. Why? Many thanks, Steven. module BrowserHelper def project_browser_helper if @project || @controller.controller_name == "projects" content_tag(:div, content_tag(:ul, build_browser), :class => "browser") end end def build_browser @browser = [] # a whole bu...

Using a Rails plugin

I want to use Peter Marklund's html test plugin to automatically validate all of my HTML pages. I'm following his README instructions and have installed the plugin successfully. However, when I use his "assert_validates" method in a test, I get the following error message: NameError: uninitialized constant Html::Test::Validator::RailsT...

Moving elements to top/bottom in sortable_element

Hi! I,m using sortable_element to sort some list with dragging and dropping, but I would like to have also some top/bottom buttons to move elements. Is there any javascript function that would act as if I dragged some element to the top/bottom of the list? ...

How can caches_action be configured to work for multiple formats?

I have a rails action which responds to requests in various formats including AJAX requests, for example: def index # do stuff respond_to do |format| format.html do # index.html.erb end format.js do render :update do |page| page.replace_html 'userlist', :partial => "userlist", :obje...

Monitoring Software for Ubuntu 8.10 on Slicehost?

I am new to server administration and I am looking for some options for monitoring my slice (ruby on rails site) on slicehost. Ideally, a live view of status and loads would be great. Any suggestions? ...

(Rails) Visually representing multitiered complex queries...?

Hi All, So I have a bit of a problem. I need to set up dynamic queries with a particular group of "entities" in Rails. And I need multiple levels for each item. Basically this particular entity relationship is as follows: CHART has many POINTS POINTS belong to many CHARTS Now, when it comes to displaying CHARTS, the application wil...

Asynchronous Actionmailer in Rails

I've noticed some of my actions (on a development environment) take a little while to load up as an email they require an email notification (through Google's servers). Do I need to implement asynchronous handling of emails like - http://upstream-berlin.com/2008/05/19/new-rails-plugin-for-making-actionmailer-asynchronous/ ...