ruby-on-rails

Rails App fails at startup?

I have an app provided by a vendor an I cant seem to start them on my local mac... I get the following error. Anyone know what I can do to get this thing working. Apu:app Apu$ script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.2.2 application starting on http://0.0.0.0:3000 => Call with -d to de...

URI doesn't validate on W3C Markup Validator, identical direct input does

I'm trying to get a site to validate as HTML5 on the W3C Markup Validator. When I use the "Validate by URI" option, it generates a ton of errors, but when I copy and paste the HTML into the "Validate by direct input", it validates perfectly. When I run a diff on the two sources returned by the validator, the only differences are the Rail...

Rails: using ZenTest / autospec to test specs in new directories

I am adding a directory for services classes in my rails application: app/services I would like to add specs for these classes in the directory: spec/services I added a spec to spec/services, but running autospec does not run the example. Is there a way to configure autospec to run examples in new directories? Thanks. ...

How to build good documentation with REST API in Rails?

Currently, I am working on building RESTful web service in Rails. I am looking for some ways to build a good documentation in my Rails RESTful web service. I found some ways to do it: Wiki like Twitter API RDoc WADL (I'm not sure if anyone is currently using it?) Could anyone gives any recommendations? ...

Is there any way for a malicious user to view the controller/model code in my Rails app while it is running?

This is probably a stupid question but I'll go ahead and humble myself. The Ruby code in my controllers and models are interpreted so that a HTML result is sent to the browser. Ok, I get that part. But is there any way for a mailicious user to somehow take a peek at the Ruby code in the controllers and models by bypassing the process ...

How can I postpone database updates in Rails?

I'm building something akin to Google Analytics and currently I'm doing real time database updates. Here's the workflow for my app: User makes a RESTful API request I find a record in a database, return it as JSON I record the request counter for the user in the database (i.e. if I user makes 2 API calls, I increment the request count...

Partial with Multiple Variables

Hi I am new to rails and need some guidance. I am sure I am misunderstanding something obvious. I would like the user name of the person who leaves a comment to show on the view page. I have a partial that goes through the collection of comments for the particular object for example a school. I can't figure out how to pass that user va...

Auto browser refresh during web development

It is well and good that the server restarts automatically for each change in the code. How would you have even the browser refresh automatically, as per configuration (Turn on and off, the least). How to do it on Windows, and on Linux, for all different development frameworks. What existing packages allow you to do it, and if you are ...

For some reason config.gem 'xapian-fu' fails despite gem 'xapian-fu' works?

For some reason when I try to do config.gem include for this particular gem package it always says its missing. I tried gem 'xapian-fu' and that works just fine! I am sure its not multi gem repository issue as I use the environment in regular basis and has no problem about this. ...

Rails Form Builders - How to display a read only field or protect a field

I have created a form that needs to show data from 2 tables (parent and child). When the form is submitted only the child fields are updated (the parent fields are meant to be display only). While the parent model fields are displayed these need to be protected from updates (preferably via the formbuilder, rather than via css). FWIW th...

Logging out after authenticate_or_request_with_http_basic in rails

How do I "log out" a user? Know that this is not officially supported, but I need a quick and dirty hack. Saw somewhere I just throw out a 401 access denied - but anyone know the syntax ...

How do I impersonate a user with AuthLogic

I need to be able to create a UserSession without having the decrypted password. How do I go about doing this? My current workaround is: In user.rb def valid_crypted_or_non_crypted_password?(password) valid_password?(password) || password == crypted_password end In user_session.rb verify_password_method :valid_crypted_or_no...

ActiveRecord: Cache and automatically update (redundant) attributes - Best Practice

Given the following ActiveRecord models: class Tree < ActiveRecord::Base # attributes: title, price, some_date has_many :nodes end class Node < ActiveRecord::Base # attributes: title, price, some_date belongs_to :tree end A Tree has many nodes (1'000 - 2'000). For performance and other reasons I'd like to cache the price attr...

Capistrano's Failure

It is the first time I use Capistrano and the application had been already published without it. When I type cap deploy:migrations I get the following error after some successful commands: * executing "cd /home/collimarco/foto-fiori.com/releases/20090818111104; rake RAILS_ENV=production db:migrate" servers: ["foto-fiori.com"] ...

Rails: Smart text truncation

I wonder if there's a plugin to enable a sort of smart truncation. I need to truncate my text with a precision of a word or of a sentence. For example: Post.my_message.smart_truncate( "Once upon a time in a world far far away. And they found that many people were sleeping better.", :sentences => 1) # => Once upon a time in a w...

Lifestream in Rails

I'm currently building a "Lifesteam" style website in Rails. A lifestream usually is an aggregate of public content (usually received via APIs). I'm currently confused about the database structure. There will be a Users table (as users will be able to sign up and have their own lifestream). I'm wondering whether I should also have a S...

Any clever workaround to avoid having to type the h method everywhere?

It seems ridiculous (and a violation of DRY) to have to type the h method all over the place in your view code to make it safe. Has anyone come up with a clever workaround for this? ...

Attachment_fu failing to validate on update

I have been using attachment_fu on a project for a long time and all was fine but now as I am trying to bring the project up to rails 2.3.3 I am running into a strange bug that is driving me nuts. The Attachment, a logo in this case, validates correctly on create but does not fail validation on update. I have debugged it and it fails the...

Executing Ruby script in an Rails application

I can run the following commands in the console for my Rails application and import CSV file into my database. require 'csv' # row will be an array with the fields in the order they appear in the file CSV.open('myfile.csv', 'r') do |row| # assuming the fields in the CSV file are in order npa, nxxFrom, nxxTo, trnk # create and s...

Ruby: TypeError: nil is not a symbol

I'm following this tutorial I'm focusing on the testing portion. I'm trying to test the following snippet: def test_disallowed_passwords u = User.new ...{some more testing code} assert !u.save <<<<<<This is line 27 The u. save should fail in this case. When I run the test, I get the following: ...