ruby-on-rails

Should I learn Rails or Merb?

Background: After taking time to reflect on the answers to a question I asked just yesterday regarding which web-focussed language to learn for a beginner (link) I decided that I would most likely pursue learning Ruby/Rails (since I had already made it 1/3 of the way through a book on it about a year ago and felt like I was able to under...

uploading a file to a website with ruby/rails

I am building a rails app to test our flagship product (also web based). The problem is that part of the testing requires using the production app's web interface to upload files. So what i need to do is have the rails app upload these files to the production application (not rails). Is there a way to have rails post the file to the p...

How can I cut a large Rails application into smaller applications that work together ?

I have worked a bit with Django and I quite like its project/applications model : you can build a Django project by assembling one or more Django applications. These applications can be autonomous, or some applications can be built on top of other applications. An application can easily rely on another application's models, as well as ...

Modeling Messages between Users

I want to model messages between users, here is the requirement: User has received and sent messages, and should be retrieved by user.received_messages and user.sent_messages Message has sender and receiver, and should be retrieved by message.sender and message.receiver. I have created the User model as: script/generate model User n...

Set a model attribute in the background, based on another attribute?

I have an Auction model with several attributes, two of which are current_auction:boolean and scheduled_start:datetime. How can I make the boolean (false by default) become true when the scheduled_start becomes the current time? Please tell me if you need more information. I'm assuming that I will need to use script/runner, but have n...

What's the feasibility of running Perl on Rails?

Rails is a great platform, but it just doesn't have the history that Perl does, so I thought it might be an interesting idea to put them together. Anybody with lots of Rails experience see any problems with this? ...

Complete Sample for ActionMailer to send email with GMAIL

I would like to test my ActionMailer class, but don't have an smtp server. I would like to use gmail to send such emails. Could someone provide a sample with all the necessary configurations both on google and whatever config files in the app. thanks ...

Simplest way to allow posting to a Rails site using MarsEdit/Ecto/etc?

I have a simple site, using restful_authentication and a simple model for the posts. I would like to use MarsEdit (or something like Ecto) to post/edit content. How would I go about this? The XML-RPC system is rather bewildering - there's a lot of different variations (Atom, MovableType, metaWeblog, Blogger, TypePad, probably others), n...

Method works in console but not in the controller ??

SORRY:: I forgot that params[:user_id] does not exist in the controller, using current_user.id ! I wrote a method that returns an array of place values for user bids, e.g., [2, 8, 10]. In the Rails console it works fine, but the instance variable from the controller returns nil to the browser. What's going on? This method returns an ...

How to call expire_fragment from Rails Observer/Model?

I've pretty much tried everything, but it seems impossible to use expire_fragment from models? I know you're not supposed to and it's non-MVC, but surely there much be some way to do it. I created a module in lib/cache_helper.rb with all my expire helpers, within each are just a bunch of expire_fragment calls. I have all my cache...

Refactor with some dynamic programming?

I have a piece of code here that i really could use some help with refactoring. I need the different methods for adding relational data in a form in rails. The code is taken from http://railscasts.com/episodes/75-complex-forms-part-3, my problem is that i need to have the methods fro both the Material model and the Answer model. So i nee...

Source for updated rails engines

What is the source (url) for Rails Engines that works with rails 2.2.2? ...

Please help with named_scope

I am having great difficulty reading the API for named scopes. Each "bid" has a user_id and an auction_id. I need a scope to return the auctions the user has bid on. Auction class Auction < ActiveRecord::Base has_many :bids named_scope :current, lambda { {:conditions => ["scheduled_start < ?", 0.minutes.ago], ...

How do you talk SQL directly to MySQL from Ruby?

I want to write a script in Ruby to clean up some messed up keys in several copies of the same MySQL schema. I'd like to do something like SHOW CREATE TABLE, then look at what comes back and delete keys if they exist. I know in the Rails environment you can do this... ActiveRecord::Base.connection.execute( some sql ) But what you get...

Trouble sorting records on unique attributes..

Working with the following code, I need to return only records where the `point' attribute is unique. I can't seem to get there by myself. uniques = Item.find_all_by_item_id(item_id) uniques.sort! {|a, b| b.point <=> a.point } # how do I reject the equal points? In other words.. I guess, how do you make [0, 1, 1, 1, 2, 3, 3, 4, 4, 7]...

Implementing sessions in rails

I'm doing a first pass at rolling my own authentication and sessions in rails and am not sure that I understand the session support that is present. (By first pass, I mean I'm initially authenticating via http, not https. Production code will use https.) My understanding of secure sessions is that you pass a token to the browser via a c...

Is it possible to load a Rails helper at run time?

I have a View that can vary significantly, depending on the 'mode' a particular user has chosen. I thought I would extract the different behavior into two different Helpers, and then have code like this in the Controller: class MyController < ApplicationController case mode when 'mode1' helper "mode1" when 'mode2' helper "mode2" e...

script/generate migration throws error about I18n in Rails 2.2.2

I have this on line 56 in my environment.rb: I18n.load_path += Dir[ File.join(RAILS_ROOT, 'lib', 'locale', '*.{rb,yml}') ] I can run the app just fine, but when I try to run: script/generate migration I get this error: environment.rb:56: uninitialized constant I18n (NameError) What gives? ...

How to hack boot.rb to stop annoying warning? Gem::SourceIndex#search support for String patterns is deprecated

Everytime I run rake or most rails commands, I get an annoying warning. I'm still a beginner with Ruby/Rails, and I would like advice on how to hack boot.rb to stop the annoying warning. I'm using Rails 1.2.6 and RubyGems 1.3.1. (I haven't upgraded Rails to 2.x because I'm still learning Rails from a book that uses 1.2.x.) I'm gratef...

Truncate Markdown?

I have a Rails site, where the content is written in markdown. I wish to display a snippet of each, with a "Read more.." link. How do I go about this? Simple truncating the raw text will not work, for example.. >> "This is an [example](http://example.com)"[0..25] => "This is an [example](http:" Ideally I want to allow the author to (...