ruby

How to make will_paginate loop back to first on last entry?

If on the last item of a collection, I'd like a "next" link that displays the first item again. ...

named_scope and HABTM association

Hi all, I have a models User class User < ActiveRecord::Base has_many :ratings has_many :rated_films, :through => :ratings, :source => :film end and Films class Film < ActiveRecord::Base has_many :users, :through => :ratings end I am looking to find all Films that have not been rated by the specified user...

How to extend DataMapper::Resource with custom method

I have following code: module DataMapper module Resource @@page_size = 25 attr_accessor :current_page attr_accessor :next_page attr_accessor :prev_page def first_page? @prev_page end def last_page? @next_page end def self.paginate(page) if(page && page.to_i > 0) @current_page = page....

Which Platform to choose Ruby on Rails or GWT?

Hi All, I have a need to create a web2.0 application with the following features: UI screens Integrate with a forum framework Integrate a blogging framework with the application Real time chat application (Optional) Integrate with a email server Based on your previous experiences, please suggest good frameworks, toolkits, etc whic...

How to produce several forms for a nested form ?

Intro I have an object @organization that has_many :quick_facts Basically, I want to produce a _form for each :quick_fact but with one save button, that saves all of the quick_facts. My two problems: First Problem: My quick_facts are not prepopulated with their information. They only appear as blank for each quick_fact I have. Se...

Lots of fields in a model, but want to have a public / private attribute for all of them.

I have a model where almost every field needs to have a public / private flag (boolean) for each item. At first I thought I'd make a boolean for each field, however, I am not sure if thats the best way of handeling this. Is there a better way? I'm up for all suggestions. ...

How to make a function call that happens only once in Ruby/Rails

A gem/plugin that I'm using to support my test suite calls some GNU commands that cause the Windows shell to roll over and die. I can rewrite these functions with a bypass in this fashion: def get_rake_output(task) if RUBY_PLATFORM.include? 'mingw' puts 'Skipped since OS is Windows. Run the test suite on a UNIX-like shell.' ''...

Problems With Sending Larger Files Over Ruby's TCPServer

I've set up a simple, single-service server which has been working just fine with small test files, but when I tried running larger, more practical files, things go wrong. Sending a 5.2 MB file works fine. Sending a 30.3 MB file works, but takes a long time (Like 15 minutes or so). When sending a 38.5 MB file, the server receives it, bu...

How to change file permission of all files in a S3 bucket using either aws-s3 gem or right_aws gem

Is there a way to change the permission of every single file in a S3 bucket using either aws-s3 gem or right_aws gem? I can't find it in the documentation. Do I have to do each file individually? I would like to grant "everyone" view permission. ...

ruby array with nil object

Can I have an array which has a nil as a value in it? For example, [1,3,nil,23] I have an array in which I assign nil array = nil then I want to iterate thru it but I can't. The .each method fails saying nil class. Is it possible to do this? ...

Ruby 1.8.7 vs Ruby enterprise

From what I understand REE is better in terms of garbage collection and much faster when combined with Passenger. Are there any downfalls of using REE as opposed to Ruby 1.8.7? Random bugs on REE? Compatibility errors? Not advisable for beginners? This is the only result I found: http://stackoverflow.com/questions/1402010/ruby-enterpri...

Problem using garb rubygem on OSX 10.6

New install of Snow Leopard, patched/updated. Updated rubygems and currently installed gems. Installed garb (version 0.7.6). On running irb I get the following: plushgraffiti:garb paul$ irb >> require 'rubygems' => false >> require 'garb' => true >> Garb::Session.login('username','password') NameError: uninitialized constant Garb fr...

Forum name not displaying...

Not sure why. My model defines the object forum def index @forum = Forum.find(params[:forum_id]) But in my view it won't display the forum name. This code just comes up with "Forum : " <h2>Forum : <%- @forum.name -%></h2> The forum database table exists, and has an object that should be displayed! mysql> desc forums; +----...

Easy Ruby data table/search question

Hello, So I have a table that looks like this: A B A C B A C A C B I want to delete the lines that the connection of two values are already in represented (so A----B is the equivalent connection as B----A). Basically I want my table to look like this. A B A C B C How can I do this in Ruby? -Bobby EDIT: H...

How can I limit the amount of words displayed from a Ruby string?

Hi there, the Ruby code is below: <%= product.advert_text -%> What script should I add then can limit the words amount? Many thanks for anyone's advice. ...

Validate words against an English dictionary in Rails?

Hi there, I've done some Google searching but couldn't find what I was looking for. I'm developing a scrabble-type word game in rails, and was wondering if there was a simple way to validate what the player inputs in the game is actually a word. They'd be typing the word out. Is validation against some sort of English language diction...

Problem installing sqlite3-ruby!

I'm having issues installing the sqlite3-ruby gem on crunchbang linux. After googling the past few hours and following several people with the same problem, I still haven't gotten it to work. Here is what I see after trying a 'sudo gem install sqlite3-ruby' Building native extensions. This could take a while... ERROR: Error installin...

Get individual JSON objects with Ruby.

Forgive me if this is a really stupid question, but how do I get individual items from a JSON GET with HTTParty? For example: require 'rubygems' require 'httparty' require 'pp' player = pp HTTParty.get('http://api.dribbble.com/players/1') will return this: {"name"=>"Dan Cederholm", "avatar_url"=> "http://dribbble.com/system/users...

How to add 'auto_increment' to another column besides 'id' in rails table defination?

If I need to add 'auto_increment' to a new column called 'another_id' in a table, how can I make it? Is there an option like: create_table :posts do |t| t.integer :another_id, :auto_increment => true # Is there a option like this? ... t.timestamps end In development env I use sqlite3, and mysql in production env; ...

Ruby Rspec outputs literal escape characters on windows

Hi all, I'm following the ruby on rails tutorial: http://railstutorial.org/chapters/static-pages#top I'm up to using rspec. Having installed the win32console gem, it outputs gibberish in the console, i assume it is outputting the ansi colour change codes: >rspec spec/ ?[31mF?[0m?[31mF?[0m Finished in 0.34376 seconds ?[31m2 examples, ...