ruby-on-rails

How to tell selenium to use test database?

I'm using selenium-client to run a few tests, but Selenium seems to be using my development database. How can I point it to use my test DB? ...

Rails ActiveResource HABTM return values

I have two models: Company and User they have a has_and_belongs_to_many relationship. I'm using active resource with a method to get all users of a company: def users @company = Company.find( params[:id], :include => [:users] ) render :xml => @company.users.to_xml(:include =>[:companies]) end The only problem is, on the other...

Configuration Issue with rails gem nkallen-cache-money (0.2.5): Get RecordNotFound exception on find method

I installed nkallen's cache-money gem per the github readme. I run into RecordNotFound exceptions during my tests. If I comment out the contents of config/initializers/cache-money.rb, the tests run fine. My cache-money.rb file is identical to that on the github instructions. Here is the contents of my config/memcached.yml: development:...

How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?

I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't. I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_js...

Best data structure and design for this feature

In my Rails app, I have a section called Situations, which is basically a textual description of a situation. But there are several of them. I want to be able to display only one at a time and each one on its own page (the newest created ones first), and then at the bottom of the page I have links that go to Older and Newer situations. ...

Auto-complete text field

How do I make an autocomplete text field like the one here at Stack Overflow for the Tags fields? I want to use it for my Rails app. ...

How do you clear a single entry from a ruby on rails session ?

In ruby on rails when doing session[:foo] = nil it leaves an entry named :foo in the session object. How can you get rid of that single entry from the session object? ...

Setting up wildcard domains on local host (OS X 10.5)?

I am starting to develop a site which basically acts as WordPress MU, in the sense that a user can signup and have their own blog. I will be coding this in Rails, however I am hoping to be able to utilize wildcard subdomains, so I can use the format such as blog.example.com. I've done some searching but I can't find any good resources. ...

How to validate an outside form field in a Ruby on Rails form (such as a captcha)?

I have a user registration form, and wanted to write a human detecting "captcha" into my register method. I decided to create a simple math question for users to answer (this should work for my purposes). How do I write a validation that checks the value of this field? I wrote a validate method in my model file as follows: def validat...

Activerecord - callback after all associated objects are saved

I have a model and I would like to store ids of associated objects (denormalize) for performance reasons. I have a method which looks like this: def cache_ids self._tag_ids = self.tag_ids end I thought I could just run it on before_save, however there is a problem - some of the associated objects might be new records, and therefore ...

Pagination and table sorting in Rails

I am using will_paginate and sort helper for pagination and sorting resp.. But im facing one problem while sorting that when im on page 2 or 3 or any other page than first page. It redirects to the first page and sorts the first page only. please help me how to sort all the records and go back to page where I was. ...

Rails console: Run a Ruby file several times

Rails provides a very useful console ('script/console'). I write a ruby file and run it in the console using require foo.rb. It works fine the first time, but the second and next require foo.rb does not run my script (require does not reload it). Do you have any tips/tricks? ...

Foreign Key Issues in Rails

Took me a while to track down this error but I finally found out why. I am modeling a card game using the Rails framework. Currently my database looks (mostly) like this: cards cards_games games ----- ----------- ----- id id id c_type card_id ... value game_id other_stuff ...

Rails: Nested namespaced resource route

map.resources :users map.namespace :formulator do |formulator| formulator.resources :submissions end I want to have submissions be a nested resource of users, but I'm not sure how to since it's namespaced. ...

How do you use will_paginate ?

Say if I have a set of objects contained in @set. Each of these objects has a description method which will return some text that I want to display on individual pages. How do I use will_paginate to paginate this? The examples I've seen so far such as: @articles = Article.paginate :page => params[:page] look like they are referring t...

has_many :through association

Is it possible to make some kinda this association: User model: has_many :goods, :through => :assignments has_many :goods_want, :through => :assignments, :source => :good, :conditions => "assignments.type = 1" Testing in console u = User.first u.goods_want << Good.first u.save This is being logged: INSERT INTO `assignments` (`goo...

Is there any use for Flex + Python/Ruby without a web framework (Django/Rails)?

I often hear about Flex being combined with web frameworks on the backend. The idea being that Flex serves as the presentation framework while the web framework (Django/Rails) does the database lookups and sends the data to Flex to present in the form of XML. However, is there ever a situation where Flex and Python/Ruby would be combine...

block always returns true

Hi all, Will always return true and erase the entire array <% users.delete_if do |user| %> <% false %> <% end %> On the other hand <% users.delete_if do |user| false end %> works and does not delete the array. Can i somehow use the delete_if statement in my view and still be able to insert html? Thanks ...

Ruby on Rails: Running Tests

When I want to run all my unit tests, I run rake test:units. To run all my functional tests, I run rake test:functionals. If I want to run all the test cases in one file, I run ruby test/unit/username_test.rb A few people have been telling me I should run rake instead such as rake test:units TEST=test/unit/username_test.rb For runnin...

activeresource error status and response body

I am making an activeresource call to a service, and I'd like some custom error messages as feedback. I have some validations that aren't normal model validations, so I can't just return @object.errors. So, for instance, one of my validations is this. Two objects have a many to many relationship, but I want to restrict one object to o...