ruby-on-rails

Upload a file to a Rails Application from a Ruby command-line application

I've been busy on a social networking site for developers for a while (like a mix of github and Facebook), and I want to implement a simple system to create repositories, like on github. For this, I want to create a command-line application in Ruby (not Rails), which will check if there were made any changes, then upload changed or new f...

Handling exceptions raised in observers

I have a Rails (2.3.5) application where there are many groups, and each Group has_many People. I have a Group edit form where users can create new people. When a new person is created, they are sent an email (the email address is user entered on the form). This is accomplished with an observer on the Person model. The problem comes...

rails: has_many with 2 relations fields

Hi I have a relation between 2 models. The models are "Category" and "Page". I have now the use case that I need 2 Pages/Category. How can I write this? The fields in Category are "page_id" and "page_en_id". I'm not sure which is the best solution for this, I only know the belongs_to and has_many solution with foreign key option which...

Should I send patch against 2-3-stable or master

I am trying to find a way to contribute back to rails. I was thinking I should validate if this patch https://rails.lighthouseapp.com/projects/8994/tickets/4154-expires_now-broken works or not. I was able to validate the problem. The problem still exists in 2.3.5 and in 2-3-stable branch of rails. I was not able to apply his patch at 2...

Cache data from a webservice in Ruby on Rails

Hi, is there a way or even a gem if I want to cache data retrieved from a webservice? The data should expire and been updated for example after one week. I have a model where I store the ID from an entry of a webservice. Then I get the data and display it to the user. But what if the webservice is unavailable? Or if lots of users uses ...

Why is while loop + sleep + ActiveRecord.find in Rails not returning records when it should?

I'm trying to implement a comet approach in my Rails application. I have the following: def poll records = [] start_time = Time.now.to_i while records.length == 0 do records = Something.find(:all, :conditions => { :some_condition => false}) if records.length > 0 break end sleep 1 if Time.now.t...

Rails Actionmailer Handling of Failed Messages

Hi, I'm using rails 2.2.2 on a linux box and am using a rake task to send some emails. It's a very simple script without error handling: 1.) Get emails to send 2.) Send email 3.) Mark emails as sent Right now, the port on the smtp server has been blocked temporarily so steps 1 and 3 are completing but not step 2. My question is, wh...

Get user email address with Facebooker?

I know the user needs to give the application "extended permission" for access to the email address. I went through the Facebooker documentation (I am using it for an iFrame app for whatever it's worth) but can't find any related stuff in the documentation or any sample code. ...

How do I DRY up business logic between sever-side Ruby and client-side Javascript?

I have a Widget model with inheritance (I'm using Single-Table Inheritance, but it's equally valid for Class-per-Table). Some of the subclasses require a particular field; others do not. class Widget < ActiveRecord ALL_WIDGET_TYPES = [FooWidget, BarWidget, BazWidget] end class FooWidget < Widget validates_presence_of :color end cl...

How to let users post links/images to Facebook, Twitter, Buzz etc... from a Rails based website?

I'd like to offer users the ability to post images / links to articles from my web application to Facebook, Twitter, Buzz and any other social network. A perfect example of the functionality I'm trying to replicate is mashable.com ... where each social network is represented by an icon that a) shows the number of shares AND b) allows us...

Sharing code between two or more rails apps... alternatives to git submodules?

We have two separate rails_app, foo/ and bar/ (separate for good reason). They both depend on some models, etc. in a common/ folder, currently parallel to foo and bar. Our current svn setup uses svn:externals to share common/. This weekend we wanted to try out git. After much research, it appears that the "kosher" way to solve this is u...

Authentication in Rails, where to start?

Hello. Im learning Rails by building apps. I want to make my first authenticated app: users signup, login, do some changes in models they have access to and logout. I did the Google search but it is quite confusing: many plugins, many tutorials. Don't know where to start. Is there a state-of-the-art authentication method for Rails? Wh...

to_xml for fully-qualified trees using acts_as_tree

I have an ActiveRecord class that uses acts_as_tree. I'm trying to update the to_xml method so that if a child record's to_xml is called it will return it's xml nested in the parent/ancestor xml to give the fully-qualified path to that resource. As an example I have Compiler which is a parent of Compiler/Version. Compiler should be re...

Rails before_filter and action identification

Hi all, I want to write a before_filter in my controller to identify the action which will execute next. This is for authorization purposes (this is somewhat like role_requirement plugin do..) Ex: if a user types this url http://localhost:3000/users, default it goes to users/index action. And in my users controller i'm having a before ...

Should I expect Comet to be this slow?

I have the following in a Rails controller: def poll records = [] start_time = Time.now.to_i while records.length == 0 do records = Something.uncached{Something.find(:all, :conditions => { :some_condition => false})} if records.length > 0 break end sleep 1 if Time.now.to_i - start_time >= 20 ...

Implementing an Online Waiting Room

My organization is building a new version of our ticketing site and is looking for the best way to build an online waiting room when the number of users in our purchase path exceeds a certain limit. The best version of this queue would let new users in after existing users have either completed their purchase or have exceeded a timeout ...

Rails - Displaying Large Set of Data in a Table / Start new column after X rows

Hi, I trying to display a large set of checkboxes in my rails app and didnt knwo the syntax for displaying like 15 rows then after starting a new column. I have a model with about 120 entries. Currently, I have it being displayed in the view as.... <% for interest in Interest.find(:all) %> <%= check_box_tag Blah Blah Blah %> <%= inter...

How do I insert an input's value into a separate form?

I'm making a tool for my university that allows students to create a list of classes by doing the following: Searching by course title for their course via an autocomplete input field. Adding that course to a separate form that upon being submitted creates a course list. I am trying to link the autocomplete and the course list form w...

Rails 3 ready to use in Production?

Is Rails 3 ready to use in Production? I know is in beta (currently beta 3), but is it suitable to build a simple app using authentication (devise)? Or should I wait for a final version? What is your opinion? Thanks ...

Rendering field data as a link in Ruby on Rails...

Ok, I think this is probably an easy question but for the life of my I can't figure it out. I have created a table called ugtags and in that table I have two columns (beyond the basics), 'name' and 'link'. I am trying to allow a user to add a link to a page. Ideally they would enter the link title (name) and the url (link) and in the vi...