ruby-on-rails

ruby on rails has_one question

Hello, I am trying to understand has_one relationship in ruby on rails. let's say I have two models - Person and Cell class Person < ActiveRecord::Base has_one : cell end class Cell < ActiveRecord::Base belongs_to : person end can I just use has_one: person instead of belongs_to : person in Cell model? isn't it same? ...

Is there a way to avoid automatically updating Rails timestamp fields?

If you have DB columns created_at and updated_at Rails will automatically set those values when you create and update a model object. Is there a way to save the model without touching those columns? I am bringing in some legacy data and I would like to set those values from the corresponding values in the (differently named) legacy data...

how to attach files that are stored in the database to the action mailer?

Hi, you have mention about how to store files in database. How to attach those files with mail using action mailer? I have search many sites but not able to find the way to attach database files. Everywhere the help of attaching files stored in file system is given. ...

Help interpreting this bit of Rails code

What is this? "#{h params[:chat_input]}" I am referring to the hash # and the h. ...

global methods in ruby on rails models

Hi All, I have methods in all of my models that look like this: def formatted_start_date start_date ? start_date.to_s(:date) : nil end I would like to have something that automatically writes a method like this for each datetime field in each model, what's the best way to do this? -C ...

How do I include a validates_confrmation_of in a Module in rails

I want to include validates_confirmation_of :password in a module but i keep getting errors like: "undefined method `validates_confirmation_of' for Password::ClassMethods:Module" Not sure how I can make it work. thanks ...

Saving the position of a draggable div in rails

After making a div draggable, i would like, when the div is dropped, to pass to the controller the div's position so that it can be saved on to the database. My first idea would be to have an hidden form within the div, with 2 text fields (one for X and one for Y) which is kept updated via javascript and submitted on drop. However this...

Rails Routes and Different XML Templates

My application needs to provide the same data in XML to 2 different providers that have specific formatting requests. What's the best way to setup my routes so that I can have the following: http://www.site.com/posts/provider1.xml http://www.site.com/posts/provider2.xml (Where provider 1 and 2 are separate templates) Thanks. ...

Rails CRUD Parameters Issue

So my background is in Java web services, but I'm trying to make the move to ROR. I'm using FlexImage to handle image uploading and thumbnail generation. I followed the guide and CRUD behavior was working fine at one point. However, at some point, CRUD behavior for one of my models (Images) was broken. The error code I'm getting back...

Clear Password Fields if errors

I have a regular signup form with virtual_attributes: attr_accessor :password_confirmation def password @password end def password=(password) @password=self.crypted_password = User.encrypt(@password=pass, create_new_password_salt) end I would like to clear the password fields of the form when there are errors on password. I figu...

Best of breed Memcache Solutions in Rails

Looking around the web I see a number of plugins and patterns for using memcached in rails. I'm working on a new project and am wondering what the best of breed solutions are. Google turns up a lot of older results, which I'm not sure are the latest and best ways of doing things. ...

How to best copy/clone an entire nested set from a root element down with new tree

I am using "acts_as_nested_set" in my rails app. (extended with awesome nested set plugin). I was trying to logic out the best way to write a function/method to clone an element and its entire nested set so that each element gets a clone but the relationship structure mimicks the original, just with the new elements. With nested sets y...

Trouble using ssl_requirement with restful_authentication in Ruby/Rails.

I'm trying to use the ssl requirement plugin with the restful authentication plugin and I have a question that I'm having trouble finding the answer to. When allowing a user to login from a non-SSL action/page, should I require SSL on the session's create action for increased security, or is that overkill? If so, how do I get the creat...

Rails: attachment_fu plugin, convert PDF uploads to image

Yo, I've got attachment_fu set up on my server, and it works just fine. My goal, however, is to be able to upload PDFs and have them convert to image (then use all the pre-built attachment_fu options like resize and thumb produce the desired images). What currently happens is that PDFs upload and remain PDFs, whereas images go through a...

Ruby on Rails functional testing with the RESTful Authentication plugin

I started writing functional tests for my rails app today. I use the RESTful authentication plugin. I ran into a couple confusing things I hope someone can clarify for me. 1) I wrote a quick login function because most of the functions in my rails app require authentication. def login_as(user) @request.session[:user_id] = user ? u...

Geokit-rails plugin - can't call to_json on returned GeoLoc object, gives circular reference error

I was using an earlier version of geokit plugin on a rails 2.3 app and just updated to this latest version - the one that now uses a gem. In the previous version it was possible to convert the object returned by the .geocode method to json. by just calling the to_json method on it. This however breaks in the new version. I noticed the...

Does validates_uniqueness_of work for generating a random token?

If I want to generate a random string for a token in rails, can I use validates_uniqueness_of on it? Given that this isn't something a user will input or get an error back for it needs to be unique straight away. Or am I just being stupid? ...

How to do site analytics with ruby on rails

I was wondering what are the options for doing site analytics with a ruby on rails application ? I haven't seen any solutions specifically targeted towards rails - more towards apache type web servers. I don't want to use the google analytics, I'd like to have the logging/analyis all local. After a quick look at wiki's list of web analyt...

Your favorite lesser-known Rails gems/plugins

What are your favorite lesser-known gems/plugins for Rails? This question about Rails plugins brought up only the usual suspects (Paperclip, RSpec, Shoulda, Restful Auth, etc). It'd be great to get a list going about the hidden, less popular ones that rock. ...

what happened to mongrel? any alternatives on windows?

I've jus saw that mongrel's last updat was about one year ago... http://mongrel.rubyforge.org/wiki/WikiStart?action=diff&amp;version=35 has it been disontinued? is there any other lightweight alternative for a windows development box? ...