ruby-on-rails

Rails resources generated url methods and parameters

Hello, I have some rails resources with complementary parameters to the :id one. For example : map.resources :users, :controller => 'users', :path_prefix => ':lang' So that I'd have the lang prefixed to the URL. The default generated url methods would be : user_url(lang, user) However the lang is always the same parameter. For exa...

What is the best RESTful way to pass string collections as parameters?

I've got a rails application with RESTful-ish URLs where I need to pass in a collection of strings (tags), and I don't want to use the query string. Currently I'm using a route similar to /controller/tagged/:tags/foo/:foo/bar/:bar.:format This requires the 'tags' to be encoded which is a pain and error prone if you want to manually typ...

Error during multipart POST between two rails applications

I am trying to perform a multipart post from one rails application to another using the following code: require 'rest_client' RestClient.post 'http://localhost:3000/users', { "user[fist_name]" => "foo", "user[profile_image]" => File.new('/test.png') }) My client app throws the time out exception and the server throws the exception sho...

Authlogic and Roles

I am developing an application which users authlogic for authentication. I would like some way of giving users roles so that I can authorize certain actions to certain roles. Is there an 'out of the box' gem or plugin that suits this or would I be better build it from scratch. What would you recommend? ...

Is it bad to hard code select tags when using option_groups_from_collection_for_select

I've been working with option_groups_from_collection_for_select and haven't seen a way to utilize it on a form tied to a model without hard coding the select tags. While I've only been working in Rails for a few weeks, it would seem like there is a better way to do this (eg. collection_select or even select). Is there a "Rails Way" to ...

[Ruby] How to match/extract domain name from messy user input?

There is a form field where users should input domain names in the form of "google.com". However, taking into consideration confused users, I want to be able to clean the input to the exact form of "google.com" in case they type in the following cases: http://www.google.com http://google.com google.com/blah www.google.com ..and other i...

Basic Rails 404 Error Page

I have been looking for a simple answer to this for a ridiculously long time and it seems like this has to be so plainly obvious and simple because no one has an easy, idiot proof tutorial. Anyway, all I want to do is to have a single 404.html static page that loads whenever ANY error is thrown. Ideally this should only happen in produ...

Can't find rmagick gem when required in script

I've recently run into an issue with mod_passenger and gems. I have a couple of gems install and I can find them in my /opt/ruby-enterprise/lib/ruby/gems/1.8/gems directory. One is will_paginate and the other is rmagick. For some reason, when my rails app starts up, it finds will_paginate just fine, but says it can't find rmagick. I...

How Efficient is ActionMailer?

I am building a tool for users to send invites for a site. Is ActionMailer the best way to send the mail? It seems to be very very slow. Anyone have other recommendations? (Ubuntu Intrepid Server) Thanks. ...

Can I use just migrations from rails to maintain a database schema?

Our application isn't going to use rails for any part of its final state, but migrations are a fantastic way to define schema in my experience, so I'd like to use just that one aspect of rails. Is this a reasonable thing to do? If not, are there any tools out there than can be used to perform the same sort of job? We have a three-stag...

How to make Rails respond to only ONE request in the same time

Our project is using Ext-js, and sometimes will send several request to Rails. This will cause an error: A copy of XX has been removed from the module tree... This may be because Rails is responding to a request whilst it has to reload some module. The error disappears in production as I suspected. I guess I can solve the problem...

Why does attr_accessor clobber the existing variables in this model in Ruby on Rails?

I was bitten by this recently, and it'd be useful to know precisely what's happening to make this happen, so others avoid this mistake. I have a model User, with a schema like so: create_table "users", :force => true do |t| t.string "user_name" t.string "first_name" t.string "last_name" t.string "email" t.st...

=button_to does not generates form if already in an other form

Using the same form partial in both create and edit in my case new and preview. partial looks somewhat like this (I use HAML) =form_tag ({:action => params[:action]}, :multipart => true) =text_field :newsletter, :title =text_area :newsletter, :body =file_field :newsletter,:attachment -if params[:action] == "preview" =butto...

What's the most commonly used unit testing framework for different types of Ruby applications?

Are the same unit testing frameworks used for different web frameworks - Rails, Merb, Sinatra, Ramaze and desktop frameworks - Shoes? And what is the most widely used unit testing framework that would work with all of the various web and desktop frameworks? ...

Does cucumber do away with the need to write unit tests?

I am a little confused by the sheer number of testing frameworks available for Ruby/ROR. I have recently watched the Cucumber Railscasts and found them very interesting. So I started having a play and then struggled to see conceptually where I would put various tests. It would seem to be quite possible to do everything that can be done...

Array.join("\n") not the way to join with a newline?

I have an array.. [1,2,3,4] and I want a string containing all the elements separated by a newline.. 1 2 3 4 but when I try [1,2,3,4].join("\n") I get 1\n2\n3\n4 I feel like there is an obvious answer but I can't find it! ...

Is Rails-2.3 stable? Does anyone have any problems with it?

Hello, I want to develop an application in Ruby on Rails. I have used rails(vigorously) a couple of years ago. since then i haven't given it a try, i have been concentrating on core ruby. At that time, Rails(1.2.x) used to be a bit slow! so my problem is whether i should go for the earlier slower version or should i try newer versions......

Can eTag be used for smart client caching in asp.net MVC as in Rails?

I've found in this screencast ¹ that you can do, in Ruby in Rails, a better client caching ² considering REST + model for filling eTag. Way more smart than render all the http body and only after all this, calculate the eTag, as usual. This property can make the client caching more model-oriented when using GET, so I think this is great...

how to make column unique and index it in Rails Migration

Hello, I would like to make a column unique in Rails migration script. What is the best way to do it? Also is there a way to index a column in table? I would like to enforce unique columns in database as opposed to just using :validate_uniqueness_of Thanks, Tam ...

How to manage Rails database.yml

What's the best way to handle the Rails database.yml if multiple people are working on the project and database locations are different (the socket in particular). ...