ruby-on-rails

approve the class type of one object in rails

Hi there, I have a simple question about rails syntax: How can I find out to which class a object belongs? I try to do someting like: if class(object) == MyClass Thanks Maechi ...

How to load a partial inside of a partial?

I'm trying to fire an AJAX request when my page loads. I'm guessing this would be best from my controller. First I open a new page.. def text_tabs_nav end This page has the ability to load by AJAX two different partials. I want to load one of them on default. So I thought maybe this .. def text_tabs_nav respond_to do |format| ...

Why doesn't include? respect eager loading for habtm associations?

I have two models, with a habtm relationship. When I create new instance and call include? on the association, rails hits the database each time. That doesn't seem very good for performance. Eg.: class Foo < ActiveRecord::Base has_and_belongs_to_many :bars default_scope :include => [:bars] end class Bar < ActiveRecord::Base has_...

'rake:test' with Multiple Database configurations in database.yml

I have a rails project that uses multiple legacy databases. I would like to perform tests that verify that the models are linked together correctly. This is being done so that the team can use TeamCity (by JetBrains) to perform automated testing. database.yaml: test: ... database: application_test ... admin: ... <% if RAILS_E...

Problems with retrieving application constants in ror using the active_hash gem and a yaml file

I am trying to create a consolidated Application Constants file which populates various dropdowns in different parts of the application. I am using the very effective active_hash gem for this (http://github.com/zilkey/active_hash) The application constants (named def_constants)file typically has the following yaml structure ####### com...

Active Record Find By Column 'OR' Rails

Is it possible to perform a find_by query using an 'or' statement? For example: @product ||= Product.find_by_upc(params[:code]) if params[:code] @product ||= Product.find_by_cspc(params[:code]) if params[:code] As something like (does not work): @product ||= Product.find_by_upc_or_cspc(params[:code]) if params[:code] Thanks! ...

how to fetch all msgid and msgstr from .pot file.

I have a app.pot file. And i want to fetch all msgid and msgstr from that file. Is there any specific and proper way to do that?? ...

Access Active Record Object Attributes in Rails Model

I have a model with the following associations: class Car < ActiveRecord::Base belongs_to :transportation_vehicle belongs_to :owner has_many :parts def scrap(buyer, part) ... end end How would I access owner and parts in the scrap method? ...

Rails: download file with "Open With" option

I'm running Rails 2.2.3. I have a controller that I am using to manage uploading and downloading files. I have successfully linked to files on the view to allow a user to download, but when the download dialog box opens, it only shows a Save File option. I'd like to have the "Open With" option available as well. I'm using Firefox 3.6 on ...

Should I be updating database information in a migration?

I've been working on a rails project, in which I need to firstly seed the database and then update the data periodically. The unfortunate problem is that I seem to want to update the same set of data multiple times. Hence I would like to use the same migration name...but the rails generator seems to complain about the naming. This lead...

Nokogiri/Ruby array question

Hello, I have a quick question. I am currently writing a Nokogiri/Ruby script and have the following code: fullId = doc.xpath("/success/data/annotatorResultBean/annotations/annotationBean/concept/fullId") fullId.each do |e| e = e.to_s() g.write(e + "\n") end This spits out the following text: <fullId>D00...

Any way around putting hidden field in forms for resources with belongs_to association

I'm learning Rails by writing simple TODO tasks aplication. Two models are: class List < ActiveRecord::Base has_many :tasks, :dependent => :destroy # ... end class Task < ActiveRecord::Base belongs_to :list # ... end Tasks are routed as a nested resources under Lists. So when a new Task is created by user a POST message is se...

To change directory inside a ruby script?

I want to create a new rails application and fire up the rails server for that application, everything from a ruby script. My code look like this: #!/usr/bin/env ruby system "rails new my_app" system "cd my_app" system "rails server &" However, when running "rails server &" the path is not in the my_app folder, but in the parent fold...

Rails params parsing, escaping needed?

I'm currently using Jquery to serialize() a form, which contains a textarea, and POST it to Rails. This works successfully in most cases, unless the textarea contains a line in quotes, on its own. If such a line exists Rails parses the contents between the quotes of that line as the params variable rather than the entire contents of th...

Ruby on Rails add_column does not add that column to existing rows

I have created this migration in Rails: class AddSocialSecurityNumberToContactTable < ActiveRecord::Migration def self.up add_column :contacts, :ss_number, :string end def self.down remove_column :contacts, :ss_number end end In my development database, which is a SQLite3 database, all the old Contact records gained t...

How to update my rails 3.0.0 beta 4 app to rails 3.0.0 RC and eventually to Rails 3?

My first problem is a bundler conflict $ bundle install Fetching source index from http://rubygems.org/ No compatible versions could be found for required dependencies: Conflict on: "bundler": * bundler (0.9.26) activated by bundler (= 0.9.26, runtime) * bundler (>= 1.0.0.rc.1, runtime) required in Gemfile All possible v...

Apache/Rails: Forwarding PKI

I have a Linux/Apache/Rails stack hosting a data service. The data service is basically a front end for multiple data sources, akin to a federated search. Queries to the service are authenticated via PKI. When handling each request, the PKI must be forwarded to each data source appropriate for the given request - each data source us...

Ruby on Rails - has one and belongs to many relationship

This question is related to ruby on rails ActiveRecord associations and how to generate those migrations. I'm trying to build a web-app for a documentation/data management system and I have two models - Arg and Descriptor. (The reason for making a descriptor an object rather than an attribute is for multiple Args to share the same descr...

Controller tests with authlogic expecting user_sessions table

I'm using Authlogic (along with Authlogic RPX) in a new Rails 3 application (beta4 , just upgraded to RC). I cannot get any of my functional tests to pass. Anytime I try to run even the most rudimentary test, I end up with this error: 4) Error: test_the_truth(UsersControllerTest): ActiveRecord::StatementInvalid: SQLite3::SQ...

Rails "script/console" vs. "script/console --sandbox"

What's the difference between just firing up a rails console with script/console and a rails console in sandbox mode with script/console --sandbox. ...