ruby-on-rails

How to go about sending email x hours after a user signs up in Ruby on Rails?

How would I go about sending an email to a user, say, 48 hours after they sign up, in Ruby on Rails? Thanks! ...

[] method of Ruby String

When I reading source code of Beast, I found a lot of code like this: <%= 'Password'[:password_title] %> It seems like a call to [] method with Symbol as input parameter to a String to me, but I didn't find such type of parameter of String [] method in the ruby API. What is this means? thanks in advance. ...

In rails, how do you stub the render method in functional tests?

I'm writing some functional tests for a controller in rails, using mocha to do mocking/stubbing. Is there a way to prevent the template from being rendered during the test, so that I can test only the code in the controller? It looks like rspec provides something like this, but I'm not using rspec. ...

Railroad diagram generator fails with "NoMethodError"

After making a few modifications to a rails app I am tinkering on, railroad stopped working. The verbose output gives some clues. I wonder if other folks have encountered this and if there are some pointers for fixing this problem. Is it a data modeling error? Is it a problem with railroad? Error log follows... railroad -vM Loading appl...

How to read source code of Rails sample project?

Reading source code of sample projects, such as Beast and Bort, are recommended as a good way to learn rails. But I found myself getting lost in reading source code of these projects, cause the included plugins might bring in some strange code without any hint, such as "require" or "include". Could you share your rails code reading exper...

Java/JRuby on Rails vs .NET 3.5... feel like I'm doing it wrong

I'm planning to develop a web-services (SOAP to C++ client) in Java with Metro/Hibernate and front it up with a web-site written in JRuby on Rails, connecting Java modules through JRuby and generally through a database. I already wrote some code and set up everything. Now, I've heard that .NET 3.5 is really powerful and after some read...

How to get a DateTime duration?

Hello, I'm baffled how to do this. I need to take a datetime object and get the duration in hours, days, whatever, to the current time. Thank you. ...

What's the best way to generate environment-specific files for a Rails project?

I have some settings I need in a Javascript file -- servers to connect to -- that changes based on my environment. For development, test, and staging, I want to use the staging servers; for production, the production servers. I already have the settings in Ruby (configured in my environment/xyz.rb files). So far, I've been dynamically...

Rails: How to observe join records that don't actually have a Model?

Dear Stack, Is it possible, using an Observer, to observe the creation of JOIN records? For example, you have a User Model that has_and_belongs_to_many Book Models. Is it possible to monitor books_users records as they are created or deleted or must I have a BookUser model to do this? Example of what I want to observe: User.books <<...

How to get a positive mental attitude towards testing?

I want to write tests for my app, though each time I look at rspec.info, I really don't see a definite path to take towards "doing things right" and testing first. I watched the peepcode videos on rspec more than once, yet it doesn't take. I want to take more pride in my work, and I think that testing will help. How can I break throug...

What do you think of an AWS based architecture

I was reading through this article: http://aws.typepad.com/aws/2008/12/running-everything-on-aws-soocialcom.html And I was wondering if this was good or bad. I am a fan of AWS myself, but I what to hear what the crowd thinks... ...

Is it possible to get the raw param string in rails?

Given the following url: http://foo.com?bar=1&amp;wee=2 What is the quickest way to get the raw param part of the url from an action? i.e. ?bar=1&wee=2 ...

When to use Helpers instead of Partials

In a rails application, in which situation would you use a partial and when would you use a helper? I find both very similar, since they represent markup fragments. Is there a convention around this? which is the 'rails way' of using them? Thanks! ...

Can you get DB username, pw, database name in Rails?

I'm writing a rake task that does some DB work outside of Rails/ActiveRecord. Is there a way to get the DB connection info (host, username, password, DB name) for the current environment as defined in database.yml? I'd like to get it so I can use it to connect like this... con = Mysql.real_connect("host", "user", "pw", "current_db") ...

How to implement a singleton model

I have a site in rails and want to have site-wide settings. One part of my app can notify the admin by SMS if a specific event happens. This is an example of a feature that I want configurable via the site-wide settings. So I was thinking I should have a Setting model or something. It needs to be a model because I want to be able to has...

rails model attributes without corresponding column in db

I have some rails models which don't need any persistence, however I'd like rails to think the model actually has attributes x, y, z so when calling methods like to_json in the controller I get them included for free. For example, class ModelWithoutTableColumns << ActiveRecord::Base def x return "Custom stuff here" end There is n...

Populating Rails Form Fields after an auto_complete field is populate

I am trying to create a form in Rails 2.2.2 that populates a field based on a choice a user has made in an 'auto_complete' field. It looks as though the observe_field functionality is what I need to use but I'm stuck on how to update the value of an existing text field. The sequence of events I am trying to model is follows: 1) Use typ...

Retrieve session with session_id in Ruby On Rails?

Hi everyone, I want to access the session of a user from a different domain than the one that I initiated the session. Can I use session.session_id of the user and then retrieve the session hash of that user ? Thank you ...

What are the major differences between Rails 1.X and 2.X

Most dead-tree books and web tutorials address Rails 1.X. I'm wondering if they are worth using to learn Rails 2.X. If so, what sections and concepts should should I avoid and what have pretty much stayed the same? ...

Adding an action to an existing controller (Ruby on Rails)

I am new to Ruby on Rails, I have completed the Blog Tutorial. I am now trying to add an additional action to the controller, called 'start'. def start end I have added a view page "app/views/posts/start.html.erb" containing nothing but simple html. When I go to /posts/start i get the following error. ActiveRecord::RecordNotFound i...