ruby-on-rails

SMTP email errors in Rails

Hi, We just had our Rails app spit an error when ActionMailer was trying to send an email: Net::SMTPServerBusy - 451 Error while writing spool file We're using our own SMTP mailservers to send. Anyone know the details on this and how we can avoid it happening again in the future or if its possible to make ActionMailer try to send the ...

Rails & Acts-as-versioned: How would you restfully revert records?

How can you revert records in a way that respects REST conventions and routing? I am looking for examples of how to setup my routes.rb and build the link & controller action to do the revert. All the examples I have found are pre-REST rails. My understanding is that I need to have revert_to_version function in my resource controller....

Problem with non activerecord associations in factory girl

I just started to use factory girl to replace fixtures when I am testing. I am working on a twitter client and I am trying to use factory girl to create the twitter objects for testing. When I create them individually it is fine. But, if I try to associate them I get the error below. Factory.define :status, :class => Twitter::Status,...

Ruby on Rails :serialize UTF8 problem

When I serialize a hash containing UTF8 strings, like this: poll.variants = {0 => 'тест',1 => '-тест-',2 => 'test # test "тест'} to an ActiveRecord field, the resulting field contains: --- 0: !binary | 0YLQtdGB0YI= 1: !binary | LdGC0LXRgdGCLQ== 2: !binary | dGVzdCAjIHRlc3QgItGC0LXRgdGC The utf8 strings get treated as bi...

Configure Rails to output HTML output instead of XHTML

How do I configure Ruby on Rails to output standard HTML code instead of XHTML when using helpers (form, javascript, css, etc.)? I don't want to have the slash at the end: <input name="email" type="text" /> ...

Normally should it be ok to install 1.86 with the one-click installer and then overwrite the install directory with 1.9? Or should I not have done that?

I used the one-click installer to install 1.86 a while back. I wanted to upgrade to 1.9 but since there's no one-click installer for 1.9 I just downloaded the 1.91 binary and overwrote my 1.86 install. Didn't work so well. I got errors all over the place afterwards. What's the proper way to upgrade (for a dummy, i.e. me)? The downloa...

Facebooker Rails plugin - Notifications

Hi. I have quite silly question: how to send notifications? For example, when I register user on my app, I want to welcome him/her with notification. ...

Rails cookie session sharing and "www.example.com" or "example.com" problem

When people access my app on www.example.com and log in, they get a cookie. I'm using the cookie option to store session on Rails. Accessing example.com (without the www), they must log in again, because Firefox does not recognize the previous session. So, what do you think is the best way to avoid this? I guess I will use a small .hta...

Mongrel vs. WEBrick

What is the difference between Mongrel and WEBrick? Which one should I use? Why does Rails ship with both? ...

How do I automatically find a user's location?

I am currently working on a show listing website. I am going to display show information by location for the user sorted in a variety of different ways. I know I could ask the user where they are located when they first sign into the site, but I've seem to notice that many sites have this capability built-in to detect location automa...

How to delete object/row with jquery (post form)

Hello, I have a model posts where users can edit and delete their own posts. My index page is a table with a few columns for each post. One of them holds a form for the delete button. Is there any examples on how you jquery submit a post/delete form with rails? I need to pass the status back to the user. Eg. posts deleted, access denied...

How do I validate a date in rails?

I want to be able to validate a date in my model in ruby on rails. However, the day, month and year values are already converted into an incorrect date by the time they reach my model. For example, if I enter February 31st 2009 in my view, when I do Model.new(params[:model]) in my controller, it converts it to March 3rd 2009. Which my m...

How to do a safe join pathname in ruby?

My development environment is in Windows, and my production of rails is in Linux. There are possibility that VirtualHost will be use. Assume that one finename need to call in /public folder with File.open('/tmp/abc.txt', 'r'). but in my Windows it should be "C:\tmp\abc.txt". How can i do a right join path with two difference environm...

Making forms in Rails

So far I've built a simple form for a user using the form_for method to wrap around my user model. But if I'm going to create a form now which doesn't doesn't map directly to any particular model, should I still be using form_for? ...

Best way to display model data in a master layout in an MVC framework

I have a simple rails app that uses a master layout for all pages. I would like to have a footer in this layout that displays data from the model, so that you can see the data no matter what page you are on. Currently I have only a single controller, with a few very simple views that are rendered into the layout with no action methods d...

GET or POST, which method to use for submitting a form?

I'm writing a web form for my Ruby on Rails app. The form has a text field, some checkboxes, a set of radio buttons and two text boxes. What are the pluses and minuses of using GET over POST and vice versa. I always thought you should use GET for retrieving the form and POST for submitting, but I've just learnt you can do both. Does it...

Layer Supertype in ActiveRecord (Rails)

Hi, I'm developing a ruby on rails app and I want to be able to excecute a method on every AR object before each save. I thought I'd create a layer-super-type like this: MyObject << DomainObject << ActiveRecord::Base and put in DomainObject a callback (before_save) with my special method (which basically strips all tags like "H1" fro...

Creating Plain .rb Files with Aptana RadRails

I have just bought a MacBook for some ruby development and like the look of Aptana Studio as a really nice IDE. The question I have, however, is that I want to know (before getting too deep into it, and potentially wasting time) is can I create plain old .rb files without the rails framework attached? Also, can I execute the ruby file ...

How do I change the default "www.example.com" domain for testing in rails?

I have a rails application which acts differently depending on what domain it's accessed at (for example www.myapp.com will invoke differently to user.myapp.com). In production use this all works fine but my test code always sees a hostname of "www.example.com". Is there a clean way of having a test specify the hostname it's pretending ...

Vanishing Ruby Gems

I'm using Ubuntu 8.10 and I installed Ruby and Ruby on Rails following the directions on this site. The exact directions I followed are no longer there as it appears the rubyonrails.org wiki has changed recently. But I installed it the long way. Installed Ruby, then Gems, then installed Rails using "gem install rails". I haven't really m...