ruby-on-rails

Rails Active Record Instance Variables

Hello My questions is in regards to this AR and its instance variable @saved class PhoneNumber < ActiveRecord::Base has_one :user validates_presence_of :number def self.create_phone_number( user, phone_hash ) @new_phone = PhoneNumber.new(phone_hash) @user = user PhoneNumber.transaction do @user.phone_numbers << @new_phone @new...

UTF-8 characters mangled in HTTP Basic Auth username

I'm trying to build a web service using Ruby on Rails. Users authenticate themselves via HTTP Basic Auth. I want to allow any valid UTF-8 characters in usernames and passwords. The problem is that the browser is mangling characters in the Basic Auth credentials before it sends them to my service. For testing, I'm using 'カタカナカタカナカタカナカ...

Get route for base class of STI class in Rails

Say I have a rails app with 3 models, Person, Place and Thing. Say the Thing uses single table inheritance, so there are FancyThing and ScaryThing subclasses. Then there are routes defined with map.resources :people, :places, :things. So there are no controllers for FancyThings and ScaryThings, the ThingsController handles either type...

How can i 'insert' a small ruby app into Ruby on Rails to make a web page?

I have a small ruby application that I made on my local machine. It uses a text file insted of a database. It's a simple app that takes in a word, processes it against the text file, and then outputs the results using puts. I would like to fit it into a RoR framework, hosted on my personal machine. I have run through some lessons and ...

How to best create an xml map of recursive directory listing in rubyonrails?

I want to build an XML map of all directories and files in my public/catalogs rails directory.(recursive map) I would like it to be constructed with basic <directory> <file> element with name attribute equal to the dir or file name. <catalogs> <file name="index.html"> <directory name="foo"> <file name="file1.html" /> <directo...

Why is Rake running a model for which I can find no test?

When I run "rake", it's loading up one of the models among all of the classes I have in my app/models directory. The thing is, it's not one I have a test for, it's just a model I have in there that is actually used with script/runner to run in the background and perform tasks for my main Rails application. At the end of the file I've got...

PHP developer learning Ruby and Ruby on Rails

I have been interested in learning Rails for some time now and feel now is as good as time as ever to dip in and actually get my hands dirty. I've spent the past week reading every free ebook on Ruby and Ruby on Rails I can find. I just finished reading Ruby Essentials. I have also been playing with http://tryruby.hobix.com/ I have ins...

ActiveRecord running different queries in production?

I have a class hierarchy looks like this: class Post < ActiveRecord::Base; end class Project < Post; end class ProjectDesignWall < Project; end There's a controller that fetches data like so: @projects = Project.find(:all, :include => [:project_image_photos,:user]) In development, this runs the following query, straight from the lo...

Web development for a Computer Scientist

I have BS in Computer Science, and thus have experience developing software that runs at the command line or with a basic GUI. However, I have no experience making real, functional, websites. It has become apparent to me that I need to expand my skills to encompass web development. I have been using Ruby to develop applications, but I ...

Group results created at a similar timestamps

In my project I would like to select records from my database and then group them together by those that occurred at a similar time to the latest record within a certain time range. For example, with a 1 hour time range. If a user created 3 posts between 4:30pm and 5:15pm, 2 posts between 1:15pm and 1:30pm, and 1 post at 10:00am I would...

Amazon Market API for ruby

Has anyone used Amazon AIM or ENS APIs? I'm having trouble finding documentation. I'd like to implement it into my rails application. ...

Should i keep a file as text or import to a database?

I am constructing an anagram generator that was a coding exercise, and uses a word list thats about 633,000 lines long (one word per line). I wrote the program just in Ruby originally, and I would like to modify this to deploy it online. My hosting service supports Ruby on Rails as about the only Ruby-based solution. I thought of host...

Linking Two Models Together in Ruby on Rails

I've been stuck on this all day. I have a setup like the one below. I'm trying to define friends using the group_memberships association. class User < ActiveRecord::Base has_many :group_memberships has_many :groups, :through => :group_memberships has_many :friends # what goes here? << end class GroupMembership < ActiveRecor...

Rails Sub-controllers?

I'm pretty new to Rails and have an issue which I can't quite get my head around as to the architecturally 'correct' way of doing it. Problem relates to what I kinda call sub-controllers. The scenario is this: I have a series of pages, on which is a panel of some form containing some information (think the user panel on gitHub top righ...

What is the best way to get data from a Ruby on Rails app into an Excel spreadsheet?

I know what you're thinking, just download the data as a CSV and import into Excel. Unfortunately what we require is for a user to choose some data from a Rails app then easily (i.e. with as little user intervention as possible - ideally a single button press) export it, and open it in an existing Excel spreadsheet that contains various...

Where do you put your app-config-files when deploying rails with capistrano and svn

I have two config-files /app/config/database.yml and /app/config/userconfig.yml i don't want to put the database credentials and userconfig in the svn-repository, so i have database.yml.dist and userconfig.yml.dist checked in. What is the best way to get copys of the dist-files in the shared-directory when deploying the app for th...

Rails: Creating a Multiple Model Form over n association levels

Can anyone tell me why the form at the end of this question isn't working like it should? Save doesn't work The select-helper doesn't select the value according to the object @kid The whole thing is based on Rails 2.2.2 and no, upgrading to Rails 2.3 to solve this problem isn't an option. :-) I used this recipe to build the multiple...

User Presence In a chat room (chat getting updated by simple polling)

We have implemented a simple chat room feature in Rails using Simple Ajax updates. Now in every chat room a message belongs to particular user. We want to show the list of users(something like user presence). Please suggest ways. We are not using Jabber,XMPP etc. The Chatroom model is: class ChatRoom < ActiveRecord::Base validates_p...

How do I create a ruby Hello world?

I know in PHP you have to intrepret a page like index.php, but in Ruby how does it work? I don't know what is the Ruby extension like index.php for PHP. Could you help me? ...

Rails Caching - XML Files?

My Rails application is running on a VM. The VM's performance is just fine with static pages. In fact, I'm running another site using Apache virtual hosting that is just serving up static HTML files and the response is adequate. However, my Rails application that is dynamically generating XML files responds very slowly. In fact, it takes...