ruby-on-rails

Find newest objects in ActiveRecord

Easy question: I need help writing an ActiveRecord find_all_by statement where I want to order things from newest created objects to oldest. As a follow-up to this question: If I saved the results into a variable @records. How do I then ask for the next record in it? I want to do something like @current_record = @records.next ...

How to assign one category to a post with radio buttons, in Rails?

Hello, newbie here, first post. I just spent like 4 hours trying to assign one category to a post (trying out a regular blog thing) via radio buttons, to no avail. The association is working fine, and ultimately I managed to get it working with a select menu, but for some reason it seems radio buttons are simply not meant for that. I ...

Creating permalinks (slugs) in Rails - why is my test failing?

I'm writing a small CMS as a Rails test project (also planning to use it for my personal website). I want SEO-friendly URLs so I have a test to verify that permalinks are automatically being created based on a page's title (e.g. About Us => about-us). I can't figure out why this test is failing, however. Here's the code (I'm using Rai...

how to make acts_as_list behave with groupings

I have a small rails app that is using acts_as_list to implement drag and drop via ajax. The app has 3 main models: forms, sections, and questions. As it is designed, forms have many sections, and sections have many questions. I want a user to be able to do 3 things: reorder the sections in forms reorder the questions in the secti...

How to parse a remote website and create a link on every single word for a dictionary tooltip?

I want to parse a random website, modify the content so that every word is a link (for a dictionary tooltip) and then display the website in an iframe. I'm not looking for a complete solution, but for a hint or a possible strategy. The linking is my problem, parsing the website and displaying it in an iframe is quite simple. So basicall...

Ruby on Rails on Ubuntu linux: creating a new class throws db error

I am a novice linux user trying to come to terms with *nix development using Ruby on Rails. I am reading an excellent book titled "Simply Rails 2" [SitePoint:lenz] and haven't had any problem until I try to create a new Story object within the rails console and I get a "no driver for sqlite3 found" error: $sudo ruby script/console Load...

What's the best way to validate multiple emails and handle errors in Rails?

In the current app I'm building I've got a textarea where a user will enter a comma-delimited list of email addresses. I'm currently splitting the list into an array and then saving one by one. But if, say, I have this input... [email protected], test@example, [email protected] ... then [email protected] will be saved, but saving test@ex...

How can I send a parameter to a before filter?

I'd like to create a before_filter method in my application controller like this... def check_role(role_name) unless logged_in_user.has_role? role_name flash[:notice] = 'Access to that area requires additional privileges.' redirect_to :back end end However, it doesn't look as though before filters can take parameters. Is ...

Redefining Helper methods in Ruby On Rails.

I have a situation where the header partial is called by the standard layout. (This is fairly common I assume) In the header is a search box - just like on stackoverlow. However, when the user is on the search page, I want to remove the search box from the header. What I attempted to do was put a method in the ApplicationHelper.rb file...

Pagination and sorting in a Rails RESTful application

Any tips on how to implement sorting and pagination on a resource in a Rails application and still keeping it RESTful? How do I map the parameters for page number and sort field in a clean way? (I am currently using map.resources :x for every resource in my app) Any other performace issues involved that I should know about? (eg. cachi...

adding a method to built-in class in rails app

I want to add a method to the Array class in a rails app. Where should I put this method? EDIT to be clearer, obviously I put it in a file somewhere, but how do I tell the rails app about where to find it? ...

CSS question. How can I get blueprint css to work rails tabnav widget?

I need a quick solution to getting some decent layout working within the tabnav widget display area. I'm already using blueprint css for other aspects of the layout but I don't have enough CSS chops to figure out how to get blueprint containers to display within the tabnav's content area. The tabnav's content area is <div class="main_...

Your thoughts on using Rails scaffold generators

I'm attempting to learn Ruby on Rails. I'm pretty confident with the basics and writing my own models, controllers and views, although I only know the basics. Lately I've found that, when I start a new application, most of my models nicely fit into the REST philosophy, and I end up just writing most of the same scaffold-generated cod...

What payment processing frameworks, like ActiveMerchant, are available for other languages?

Rails has frameworks such as ActiveMerchant and Freemium (which uses ActiveMerchant) to simplify dealing with payment processing. What other frameworks are there for other programming languages such as PHP or Python? ...

How to relate multiple models to one model that will rule them all, in Rails?

Let's say I have four completely independent models (Movie, Book, Game, Album) that control the types of things I have in my media collection. With them I can CRUD and tag individual albums, movies etc. But I need to keep track, and do some stuff that is common to, all of them. So I figured I need an Item model that would give me a tabl...

How to set a cookie on a separate domain in Rails.

How can you set a cookie on a different Domain that is calling my site with a javascript call? It works in FF3, but not in IE6. My server is called from a javascript tag on a seperate site and domain. The result returns javascript that populates their page with data (it's a widget). I am trying to set a cookie using domain=".mydomain....

What is the best Ruby on Rails environment for a Visual Studio user?

I've been a Visual Studio user since 1997, and used VB 3.0 before that. My whole professional life has been spent inside the Microsoft development environments. Now I would like to branch out into Ruby on Rails to try something different, and it doesn't have the kind of vendor support that C# does (for very obvious reasons). For someon...

Single sign on for multisite application across domains in rails 2.3.2

There's a rails recipe that illustrates how to do this in rails 2, but now that sexy rack is in, the solution seemed no longer relevant. How can this be handled in rails 2.3.2? ...

How do you use the :dependant option with a many-to-many relationship?

I have a many-to-many relationship like this: class Event < ActiveRecord::Base has_many :calendar_events has_many :calendars, :through => :calendar_events # ... end I want to make it so that when I call some_event.destroy Rails deletes the association records from the calendar_events table. Based on the API docs, I'm assuming yo...

Starling: How to speed up the queue

I've launched a website today which makes heavy use of Starling and Workling to handle the background task queue. Traffic has been heavy and although my server CPU/memory has not been under too much strain, the job queue is seriously backing up. I am inexperienced with both Starling and Workling and urgently need to understand how I ca...