ruby-on-rails

Is there any way to create a form with formtastic without a model?

I would like to use formtastic to create form but I don't have a model associated with that (login form with username, password and openid URL). Of course I could create a model to do that but that model was just a hack without any useful code in it. ...

is there a semantic difference between semicolons and return characters in ruby

Hi I have a strange situation here: # Is there a semantic difference between these 2 in ruby? class MyClass < ClassThatExtendsActiveRecordBase ... # code snippet A: def image_width(size); self.image.width(size); end # vs code snippet B def image_width(size) self.image.width(size) end end I have a situation where code...

Rails validation page causes a routing error

I have a view with the flexigrid component on it. When the view calls the mickey_mouses_controller#new action, the flexigrid component calls mickey_mouses_controller#grid_data action (via localhost:3000/mickey_mouse/grid_data) and returns the relevant json objects correctly. However, when I submit my view so the ActiveRecord validations...

Sending a Javascript request in rails

Im trying to make a system that informs the user of any new private messages, the index method of the messages controller creates to instance variables of @messages and @newmessages, both are used in index.html.erb and i want to make it so that index.js.erb makes the flash message box on my site appear. Ive got jquery to run a function ...

rails, prototype, preload remote called pictures

I'm using periodic_remote_call and it updates a div with pictures. How Can I get these pictures to be preloaded? ...

Ruby gsub function

Hello I'm trying to create a BBcode [code] tag for my rails forum, and I have a problem with the expression: param_string.gsub!( /\[code\](.*?)\[\/code\]/im, '<pre>\1</pre>' ) How do I get what the regex match returns (the text inbetween the [code][/code] tags), and escape all the html and some other characters in it? I've tried thi...

How to rename a database column in rails using migration?

I wrongly named one column as hased_password, should have been hashed_password instead. Can i use migration to correct it? ...

One to many relationship in ROR

I have a "category" table that contains different kind of "product", so I create this in the category.rb: class Category < ActiveRecord::Base has_many :products end And this in product.rb: class Product < ActiveRecord::Base belongs_to :categories end I would like to know how can I get the :categories From the product in the pro...

Rendering view of controller in another controller in Rails

The same question has been asked many times, but I am unable to find a solution that works for me. I have three models, posts, users, and picture (paperclip). I use restful_authentication and set it up so that each user sees only his/her post in posts/index. I've also given him the ability to upload a profile picture. My question is h...

Which version of Ruby should I be using now (Jan 2010)?

I have vanilla Mac OS X Leopard which comes with 1.8.6. I am new to RoR so will be following tutorials on the net. Am I likely to find problems following them when using later versions of Ruby? I am currently looking at this one which mentions 1.8.6 and 1.8.7 - http://www.railstutorial.org/book ...

Custom validation messages for Session model in Authlogic

What's the best way to override validation messages for login/password in the Session model in Authlogic? In the User model Authlogic provides the merge_ methods to override validation options, but Session does not have anything like that. Any suggestions? ...

Rails: undefined method `map' for Ingredient

Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit. There are three units, lbs, gallons, and dozens, and each ingredient has exactly one unit. I think I got the associations/routes set up correctly. When creating a new ingredient, I need to require the user to set the units from these three. I used a...

Implementing a Leaderboard

Users on my site create annotations for rap lyrics (example). I want to create a leaderboard to reward the people who create the most annotations. The leaderboard should track how many annotations each user has created overall, as well as how many he has created in the past week, day, etc. I have no problem implementing the overall lea...

How can I validate the data calculated on the basis of associated models

Hello, I have a posts model which has_one reposts and has_one sponsored. User can purchase reposts and sponsored posts while creating a post. I want that the minimum purchase(sum of reposts and sponsored purchases) be atleast 1$. so i want to validate this in the post model but i can't figure out on how to write such ...

Compressing a hex string in Ruby/Rails

I'm using MongoDB as a backend for a Rails app I'm building. Mongo, by default, generates 24-character hexadecimal ids for its records to make sharding easier, so my URLs wind up looking like: example.com/companies/4b3fc1400de0690bf2000001/employees/4b3ea6e30de0691552000001 Which is not very pretty. I'd like to stick to the Rails url ...

Capistrano is removing the latest deploy

I'm having a weird problem. I do a deploy and then the dir that just got uploaded is then deleted by the cleanup task. I haven't deployed to this site in well over a month but I didn't change the deploy recipe. Any ideas? Here's the output. http://gist.github.com/267850 ...

has_many build method, Rails

Another newbie question. The goal: each ingredient can have zero or more unit conversions tied to it. I want to put a link to creating a new unit conversion on the page that shows a specific ingredient. I can't quite get it to work. Ingredient Model: class Ingredient < ActiveRecord::Base belongs_to :unit has_many :unit_conversi...

Rakefile not getting deployed with capistrano

I am getting this error when deploying with capistrano: executing "cd /opt/my_app/dev/releases/20100103021722; rake RAILS_ENV=staging db:migrate" servers: ["96.30.33.84"] [96.30.33.84] executing command ** [out :: 96.30.33.84] rake aborted! ** [out :: 96.30.33.84] ** [out :: 96.30.33.84] No Rakefile found (looking for: rake...

Date/Time conversion problems from Rails to Flex?

I am getting the following error: TypeError: Error #1034: Type Coercion failed: cannot convert "2010-01-02 23:28:17 UTC" to Date. I am using WebORB to transfer data between Rails and Flex. The data coming from Rails is of type: 'ActiveSupport::TimeWithZone'. I am trying to assign it to a Flex 'Date' data type. What am I missing? ...

.build method doesn't want to do both _id's when object has two :belongs_to...??

Hi, I have an object called Review which :belongs_to two objects: Users and Vendors. In other words, there is always a vendor writing a review for a specific vendor. When I create a review, I tried to use the .build method to presumably add the foreign_key at the time the new record is created for review.vendor_id and review.user_id. ...