ruby

Best Permalinking for Rails

What do you think is the best way to create SEO friendly URLs (dynamically) in Rails? ...

How can I "Pretty" format my JSON output in Ruby on Rails?

I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. Right now, I call the to_json method and my JSON is all on one line. At times this can be difficult to see if there is a problem in the JSON output stream. Is there way to configure or a method to make my JSON "pretty" or nicely formatted in RoR? Thanks....

Ruby code for quick-and-dirty XML serialization?

Given a moderately complex XML structure (dozens of elements, hundreds of attributes) with no XSD and a desire to create an object model, what's an elegant way to avoid writing boilerplate from_xml() and to_xml() methods? For instance, given: <Foo bar="1"><Bat baz="blah"/></Foo> How do I avoid writing endless sequences of: class Fo...

In Rails, after using find with :select, my objects don't save

Running something like: @users = User.find(:first, :select => "name, lastname, salary") for @user in @users do @user.salary = 100000 @user.save end After this looking up in the Mysql table, the users aren't updated. ...

What is your preferred way to produce charts in a Ruby on Rails web application?

I'd like to add some pie, bar and scatter charts to my Ruby on Rails web application. I want want them to be atractive, easy to add and not introduce much overhead. What charting solution would you recommend? What are its drawbacks (requires Javascript, Flash, expensive, etc)? ...

if you reimplemented twitter, what would you do differently?

I just saw the hilarious "The Rise and Fall of Twitter" which made me think: if you reimplemented twitter, what would you do differently? What technologies would you use? What languages? How do you ensure that the service is scalable? What else would you change? ...

How best to generate a random string in Ruby

I'm currently using the following to generate an 8 character pseudo random upper case string [A-Z] value = ""; 8.times{value << (65 + rand(25)).chr} but it looks junky, and since it isn't a single statement it can't be passed as an argument. To get a mixed case string [a-zA-Z] I further hack into it with value = ""; 8.times{value <<...

Project in Ruby

I've been coding alot of web-stuff all my life, rails lately. And i can always find a website to code, but i'm kind of bored with it. Been taking alot of courses of Java and C lately so i've become a bit interested in desktop application programming. Problem: I can't for the life of me think of a thing to code for desktop. I just can't ...

How do you do performance testing in Ruby webapps?

I've been looking at ways people test their apps in order decide where to do caching or apply some extra engineering effort, and so far httperf and a simple sesslog have been quite helpful. What tools and tricks did you apply on your projects? ...

Renaming controllers in Rails and cleaning out generated content.

I was following along with the railscast regarding the restful_authentication plugin. He recommended running the command: script/generate authenticated user session Which I did, and everything generated "fine", but then sessions wouldn't work. Checking the site again, he mentions a naming standard and listed updated code which stated:...

How to Implement a Redirect on All Requests (on certain conditions)?

I want to set something up so that if an Account within my app is disabled, I want all requests to be redirected to a "disabled" message. I've set this up in my ApplicationController: class ApplicationController < ActionController::Base before_filter :check_account def check_account redirect_to :controller => "main", :action =...

Which language is most like PHP?

I am a PHP dev looking to pickup a new language, I have tried and failed on C++ several times (possibly for my overall lack of interest). I've been hearing a lot about Python, and Ruby and my question is this: Which of these languages (Python, Ruby) should be easiest for someone with a background in PHP to learn? Update (6 months later)...

How do you pass arguments to define_method?

I would like to pass an argument(s) to a method being defined using define_method, how would I do that? ...

How does has_one :through work?

I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through => :pack_release_items end class Pack < ActiveRecord::Base has_many :pack_release_items has_many :release_items, :through=>:pack_release_items end class PackReleaseItem < ActiveRecord::Base belongs_to :pack belo...

http PUT a file to S3 presigned URLs using ruby

Anyone got a working example of using ruby to post to a presigned URL on s3 ...

A visual MySQL tool for Ubuntu

Hi all I have recently installed Ruby on Rails on my new Ubuntu machine (first time for me) and i was working through a demonstration on setting up a sample blog. Basically, i came to the part of setting up the mysql database and would rather use a visual MySQL tool to do this rather than command line. What is best to use? and how do ...

Ruby on Rails Migration - Create New Database Schema

Hi I have a migration that runs an SQL script to create a new Postgres schema. When creating a new database in Postgres by default it creates a schema called 'public', which is the main schema we use. The migration to create the new database schema seems to be working fine, however the problem occurs after the migration has run, when ra...

XMP library for ruby

Hi All, Could any one recommended an open source library that allows me add XMP metadata to JPEG images? Thanks. ...

Rails or Django? (or something else?)

I'm interested in learning a web framework. The two big ones, as I gather, are Rails and Django. Which one is better/faster? Is one better designed or more logically consistent than the other? Is there another framework I should look into? How easy is it to set up and administer a Rails or Django server, and how easy is it to find a shar...

How do I get CTRL-LEFTCLICK navigation on Ruby to work in IntelliJ 7?

In IntelliJ when editing Java files, this works for me. e.g. CTRL-LEFTCLICK on an identifier takes me to where that identifier is defined. For some reason it doesn't work when editing Ruby code. Any ideas? ...