ruby-on-rails

Autocomplete with local data in Rails

In my application, users pick train stations from an autocompleting text field. Since there aren't many train stations (~100), I'd prefer for the field to autocomplete based on the contents of a client-side array rather than querying the server each time the user types a character (the goal is to make the autocomplete more responsive). ...

Is Ruby on Rails supported by most hosts?

I'm considering shifting from PHP to Rails. Does an average web host support the Ruby language and everything that Rails needs? Does a normal Rails app using MySQL or does it handle data differently? And is it as "easy" to get an app up and running, as PHP? ...

Tricky ruby on rails problem. Does an easy solution exist?

I hope my question is understandable, else I'm glad to clarify. We have this sport event coming up, and I have the pleasure to register the people. :) Facts: one can have a team of 5-10 persons. Need to know the order in which the people start. Need to know who the team leader is. I did a form in the following style: o [____Write...

Rails Migrations: Load default data

Best way to load seed data? I have an Author table that is tightly coupled with a Users table. I also have migrations to alter both of these tables. I want to add a default admin user but I want to make sure that both tables are created and all migrations have run for these tables before my CreateDefaultAdmin (or whatever) migration runs...

Plugin for declaratively specifying an API in Rails like django-piston

Is there a gem/plugin for defining an API in Rails? I know you can have "RESTful routes" and render to different formats in controller actions, but I'm looking for a more all-around solution, including but not limited to the following: I would like to declare which models to expose (arbitrary resources could also be declared, but conve...

Equivalent of Django Signals for Rails?

In Rails, the closest I've seen to Django Signals are Observers. The problem with them is that they're restricted to triggering callbacks on hardcoded events related to a model's lifecycle. Django signals can be created anywhere, triggered anywhere and handled anywhere. The model lifecycle callbacks are just regular signals that happen ...

Refresh Button on a Rails View

Hi, I have a list view in my RoR web app. The view is a result of a scaffold operation. I want to add a button that will refresh the page. I prefer not to use javascript for this one, is there another way? Creating a button via button_to or form_tag ends up adding a new blank row in the database when it is clicked. Thanks! Shay. ...

How to generate unique anonymous usernames in RoR?

Hi, I'd like to generate unique, anonymous usernames when creating an instance of my User model. Ideally, it would be set by default if I don't specify any username. So for example when I do User.create!() I'd like to have the username column set to 'anonymous123', where 123 is a unique number taken from a sequence (the value of the i...

How do you consume a json or xml web service in Rails or Ruby?

An external web service is sending json or xml towards my app. What would be the best way to consume this data? Is there a built-in library in Rails or Ruby to do this or do I need to use a gem for this? ...

Is it possible to make caches_action work for a rails controller method accessed via HTTP POST?

I have a controller action which could benefit from caching. However, when I turn on action caching via the usual: caches_action :myaction, :expires_in=>15.minutes ...caching doesn't get invoked. It looks like this is because the action is invoked using an HTTP POST. For similar actions invoked using HTTP GET, caching works fine. I...

When to make models RESTful?

Just wondering -- how do you know when to add map.resources for a particular model? All of them? The ones you want to be accessible by a public API? Thanks. ...

set method to PUT in rails XML requests

if I do this: curl -X POST -H 'Content-type: application/xml' -d '<person>...</person>' 'http://0.0.0.0:3000/people/12?_method=PUT' I get "Only get, put, and delete requests are allowed." Why? Rails 2.3.2 ...

Weird Ruby Enterprise Edition Problem

I just installed Ruby Enterprise Edition and Passenger on an Ubuntu Hardy 8.04 VPS. As far as I'm aware, the installation was successful. My Rails application is accessible and on the whole, works fine. However, the part of my application where users can post comments using AJAX doesn't work. My Comment model has a setter method for the ...

Ruby url to html link conversion

I'm building a simple chat app with Rails. when a user types in a url, I want it to be output as an html link (ie, "url"). I was wondering if there is any library or well known way to do this in Ruby. If not, I've got some decent regex sample code to work with... ...

How to convert the following ruby code into Rails plugin?

#!/opt/ruby_ee/bin require 'rubygems' require 'twitter' require 'net/http' require 'uri' require 'httparty' module FbTweet def FbTweet.tweet(url) bitly_url = Bitly.shorten(url) httpauth = Twitter::HTTPAuth.new('username', 'password') base = Twitter::Base.new(httpauth) base.update("Testing to port this into rails plug...

how to delay the creation of the association until the subclass is created in active record?

I have four tables: jp_properties, cn_properties, jp_dictionaries and cn_dictioanries. And every jp_property belongs to a jp_dictionary with foreign key "dictionary_id" in table. Similarly, every cn_property belongs to a cn_dictionary with foreign key "dictionary_id" in table too. Since there are a lot of same functions in both proper...

How to retrieve a cell's height using Prawn & Prawnto?

I'm a little stuck on using Prawn/Prawnto to generate PDF documents. The Prawn documentation has helped some, but the Prawnto documentation is seemingly offline these days. I am trying to find a way to space text cells based on the previous cell's height. Prawn has the methods to do this -- no problem, but the return value from doing ...

how to use 'constantize' in custom controller module

I have a module like this: module Controller module LocaleModels def self.included(base) base.send :include, InstanceMethods end module InstanceMethods def locale_Lexeme; constantize_model('Lexeme') end def locale_Synthetic; constantize_model('Synthetic') end def locale_Property; constantize_model(...

"Cheatsheet" or checklist for Rails beginner?

I have recently begun the process of trying to learn Ruby/Rails and have been making my way through Agile Web Development with Rails (3rd Ed.). While the content of the book is great I really wish I had either a cheatsheet or a checklist of some sort that describes the steps one should take in order to create an application, and the prop...

How to get caches_action to set expires headers when there is a hit in memcached?

I have an action which I cache using caches_action :my_action, :expires_in=>1.hours and also set the expires headers in the action itself using def my_action ... expires_in 1.hours send_data(...,:disposition => 'inline',:type => 'image/png',:filename => params[:title]+".png") end However, when I look at the cache control r...