ruby-on-rails

Rails Ajaxy File Upload

Is there a defacto way of doing an Ajaxy file upload in Rails? (I say "Ajaxy" because it can't really use XHR). I've read about various approaches and plugins. Wondering what's the cleanest/most approved of by the community. Thanks! ...

Which international city has the most Ruby on Rails jobs?

I would like to ("need to" might be a better way of putting it) move to a city where I have a better chance of finding my first Rails job. Within the United States, my best guess is maybe San Francisco. Outside the US I have no idea, although I want to avoid countries where wages would not be on a par with the US. How could I determin...

How do you validate uniqueness of a pair of ids in Ruby on Rails?

Suppose the following DB migration in Ruby: create_table :question_votes do |t| t.integer :user_id t.integer :question_id t.integer :vote t.timestamps end Suppose further that I wish the rows in the DB contain unique (user_id, question_id) pairs. What is the right dust to put in the model to accompli...

Reconstruction User based Modular Website

I am developing a website in Ruby on Rails, MySQL, and Javascript. The website is modular, meaning that a user can customize their homepage and drag and drop one module to another area where it will live. there are three columns where the module can be dropped. (Think iGoogle or Netvibes) What is the best way to store this data, so th...

How to monitor passenger / mod_rails processes?

Hi there, I searched the site already but couldn't find any suitable information. As there is always some expert around I'm sure one of guys knows exactly what I'm searching for :-) We're on a balanced system: Machine 1: HAProxy load balancer Machine 2 & 3: Apache mod_rails and (of course) our Rails applications Those were the d...

Deploying a rails app to multiple locations

I'm trying to deploy the same rails app to two different locations with different app names, different logos, different stylesheets, etc. I've got the code working based on an APP_NAME and a HOST_NAME variable I store in environments/production.rb. Now I need to actually deploy it, and I need a better solution than manually editing the ...

undefined params and session hashes in before_filter

Does anybody know why, when using ruby-debug by calling debugger in a method called as a before_filter, the params and session hashes are not defined? class MyExampleController < ActionController::Base before_filter :test_hashes def test_hashes pp session pp params #both work as expected.. debugger #calling the ...

Is it possible to create a list of months between two dates in Rails

I am trying to create a page to display a list of links for each month, grouped into years. The months need to be between two dates, Today, and The date of the first entry. I am at a brick wall, I have no idea how to create this. Any help would be massively appriciated Regards Adam ...

Alternatives to use polymorphism in Ruby on Rails...

I'm currently writing some intranet web application where people could submit to admins requests for adding different resources. The example requests would be: installing programs, in this case user will select which program he wants installed increasing quota, in this case user will just enter the amount of disk space he needs or may...

I am using rails appln with Ext-JS as frontend and require help for compression

I have a rails appln which uses ext-js for front end. I have no problem in running the application. But since ext-all.js is bulky, it takes more time to load. I tried to build a custom ext-js but did not make much of a difference in size of the ext js script. I was trying with rails cache since i use rails 2.x. For normal js files, it...

Rails: macro style functions

Hi, In models and controllers, we often use Rails macros like before_validation, skip_before_filter on top of the class definition. How is this implemented? How do I add custom ones? Thanks! ...

Why does rails split my model named menuitem into menu_item when i run generate/scaffold? Is it breaking my app?

When I generated a scaffold for a model class named menuitem, it generates a class file for menuitem, but in the database creates menu_item and refers to the class in the views and controller as menu_item. This may be causing me quite a headache as im genereating a newsted show link, but its failing telling me missing method. The rake ro...

Best Practices for using partials in Rails

In keeping with the DRY-principle I try to use partials as soon as I am repeating a particular pattern more than once or twice. As a result, some of my views consist of ten or more different partials. I am worried that this might have a negative effect on the overall performance. Some programming books compare the use of partials with th...

Rails: Saving the contents of a binary field to a file

I have a model with a binary field that contains a file. I'd like to save this file to disk as part of a process I need to do. For some reason, I can't find anything on how to do this. The model contains a filename field and a file_contents field. I'd like to do something like this: model = SomeModel.find :first model.file_contents.sav...

what's the best way to force a domain with a rails app? ex: example.com instead of www.example.com

My rails app seems to break when it answers on www.example.com, it previously was working fine with just example.com...however I've moved servers recently and would like to know the best way to redirect all www.example.com requests to go to http://example.com/.../ thanks. ...

RoR table inheritance?

Scenario: I have a users table in my application. I also have two subclasses of users, lets say contributors and viewers. Each user group must have an entirely different set of attributes but they both share certain user properties (login, password, name). What is the best way to implement this using Ruby on Rails? I think single ta...

Passing data via instance variable from the controller to the view, what am I doing wrong?

I'm trying to write my first custom controller action and am running into a NoMethodError. The scenario: PostsController, with the standard 7 actions scaffolding generates. I want the index page to show a single post instead of displaying a list of them. Each post has a "visible" checkbox. I created a named_scope called visible in the...

Why do Rails migrations define foreign keys in the application but not in the database?

If I define a Customer and Order model in which a Customer "has many" Orders and the Order "belongs to" the Customer, in Rails we talk about Order having a foreign key to the Customer through customer_id but we don't mean that this is enforced in the database. Because Rails does not define this as a database-level constraint, there is ...

Rails find query with no duplicates

How do I change the following bit of code so that I only have records with distinct sender_id and message_id combinations: @roles = Role.find_all_by_simulation_id(session[:sim_id]) @messages = RolesMessages.find(:all, :conditions => ["sender_id IN (?) ", @roles.map(&:id)], :order => 'created_at DESC') ...

How to determine last object in each loop?

In your typical each loop in Rails, how do I determine the last object, because I want to do something different to it than the rest of the objects. <% @stuff.each do |thing| %> <% end %> ...