ruby-on-rails

Rails applicaiton behing proxy

I'm implementing Rails alumni application with Facebook API support. One of the requirements is to post a message from the application directly to facebook wall. Everything seems to work fine, however there is one issue which I can't fix. When I'm working at the University, I got an error "No connection could be made because the target m...

Best way to encode URLs?

Hi, I am currently developing a CMS and want to encode special chars in the URL in a nice way. I don't want to use Rack::Utils.escape. Is there already a cool gem available? Best regards ...

Establishing a has_many relationship in Rails

I'm having trouble creating an application in Rails. This application has two models, one to represent companies and the other to represent products. Each company sells zero or more products and I'm looking to capture this relationship in the model. Here's what I've got so far: I created the models by running the generator: script/gen...

Cucumber::Rails::World NoMethodError for IntegrationTest methods

I have a set of Cucumber features that are successfully running on a Mac OS X 10.5 machine and a Windows XP machine. I tried running them on a Mac OS X 10.4 machine today and Cucumber can't find any of the ActionController::IntegrationTest methods on the Cucumber::Rails::World. I am receiving the following error when trying to send a ge...

Python after Ruby on Rails

I have been working with Ruby on Rails for over a year now and have been offered some development work with Python. I would like know if development with Python is as enjoyable as Ruby in terms of the clarity and ease of use. And how well is Python suited for Web development. I've heard of Pylons being a direct port of the Rails framewor...

Does grit have to be on the same server as the repositories?

Just looking at http://github.com/mojombo/grit Curious, if grit is on a web server, and the git repositories are on another, will this still work or it HAS to be on the same server? Or does it use remoting somehow? ...

How do you validate the presence of one field from many

I'm answering my own questions - just putting this up here for google-fu in case it helps someone else. This code allows you to validate the presence of one field in a list. See comments in code for usage. Just paste this into lib/custom_validations.rb and add require 'custom_validations' to your environment.rb #good post on how to d...

transitive rails associations and magical count

In Rails, to automatically count associations, you do: class Script has_many: chapters end class Chapter belongs_to :script end and you add a Chapters_count column into the Script model. Now, what if you want to count the number of paragraphs in a Script *without having a script_id key in the paragraph model ?* class Script ha...

AuthLogic one time password (persistence_token) - what config is required to use this?

Hi, Can anyone confirm what config exactly is required to make the one time password (persistence_token) work? From what I can work out so far it is the following, however this isn't working for me so I must be wrong: pass an additional URL parameter of "user_credentials=xxxxpersistence_tokenxxxx" question - are there any other URL p...

Array to hash of key value pairs in ruby

From a model that returns all the values from a table, how would I convert that to a hash of name value pairs {column_value => column_value} e.g. [{:id => 1, :name => 'first'}, {:id => 2, :name => 'second'}, {:id => 3, :name => 'third'}] to (specifying :id and :name) {'first' => 1, 'second' => 2, 'third' => 3} ...

How to validate a model's date attribute against a specific range (evaluated at run time)

I have several models with a date attribute and for each model I'd like to validate these dates against a given range. A basic example would be: validates_inclusion_of :dated_on, :in => Date.new(2000,1,1)..Date(2020,1,1) Ideally I'd like to evaluate the date range at runtime, using a similar approach as named_scope uses, e.g: valid...

why am I getting 'wrong number of arguments (2 for 1)' after upgrading from rails 2.0 to rails 2.3.3?

This is happening in an after_save method in one of my models, PlayerAction. I didn't change any code during the upgrade (famous last words). It appears to be happening on the following line: if self.action_type.id == 1 The PlayerAction model has a belongs_to :action_type Changing action_type.id to action_type_id fixed that problem...

What is the formal design pattern behind "monkeypatching"?

Core CS question here: of the Design Patterns listed in Gamma, etc, which (if any) cover monkeypatching? Additionally, for what class of problems is monkeypatching appropriate vs. subclassing? Patching bugs in core library classes is one, are there others? I hear lots of sturm und drang about monkeypatching on stackoverflow, most of you ...

Why can't my Rails app find the gems that are packaged with it?

I've got a Rails app making use of Cucumber and RSpec. We are storing the gems under vendor/gems and trying to get the app building (running tests) in a CI server. When I try to run our tests I'm getting the following error: Missing these required gems: cucumber >= 0.3.11 rspec-rails >= 1.2.6 When I run RAILS_ENV=test rake gems...

Freezing database with Rails application

So for a class I have to turn in my Rails application to my professor. What is the best way to make sure everything goes smoothly when he trys to start it up? Also, is there anyway I can freeze a database and send that with it so he has all of the data I have been using in the application? Thanks a lot. ...

Instance variables in layout

Hello, I am fairly new to rails so I apologize if I am using the wrong terminology. I have a model Menuitem that I would like to display the contents of in a layout. How does one go about passing an instance variable into a layout? I was looking for a layout helper of some sort but I was unable to find anything. I was also looking at d...

Rails has_one :through assignments trigger a "undefined method `update_attributes'" error.

I can't figure out why rails has_one :through associations don't accept assignments. Here is the error: >> u = User.new => #<User id: nil, created_at: nil, updated_at: nil> >> u.primary_account => nil >> u.primary_account = Account.new NoMethodError: undefined method `update_attributes' for #<Class:0x1035ce5f0> from /Library/Ruby/Ge...

Ruby on Rails: Routing for a tree hierarchy of places

So we've got a legacy system that tracks places with IDs like "Europe/France/Paris", and I'm building a Rails facade to turn this into URLs like http:// foobar/places/Europe/France/Paris. This requirement is not negotiable, the number of possible levels in unlimited, and we can't escape the slashes. Setting up routes.rb for http://foob...

Obscure your Ruby code?

I am in the middle of developing an enterprise application using RoR (first time for us to build an enterprise app on RoR instead of Java), and while we do not have that much problem of obscuring the source code, I was still wondering if this was possible. Whether we could somehow just have a simple EXE or something else, such that our c...

Good Fileupload plugins for rails

Would appreciate inputs on the best file upload plugins with support of atleast following: Resizing images. Flexibility of specifying the place of storage. Nice AJAX progress bar integration. Multifile uploading facility. Thanks. ...