ruby-on-rails

Validating a legacy table with ActiveRecord

Good day all, We are doing a data migration from one system to a Rails application. Some of the tables we are working with are very large and moving them over 1 record at a time using ActiveRecord takes far too long. Therefore we resorted to copying the table over in SQL and validating after the fact. The one-by-one validation check ...

Any view code ideas when using state machines?

I've been trying to implement a guided (wizard-like) interface to collect information to populate several models. I've found a decent amount of information on the various state machine plugins, but only one example on how the state machine can be used to control the view. (The Advanced Rails Recipe book from Pragmatic Programmers). I'm ...

Phusion Passenger on Ubuntu not seeing plugin in vendors directory

Phusion Passenger, running on Ubuntu Hardy Heron, is bombing on a require 'lingua/en/readability'. The plugin is installed in the plugins directory and works fine with script/server, just not Passenger. Error Message: source file that the application requires, is missing. * It is possible that you didn't upload your application file...

Should I disable mod_rails for images and stylesheets directories?

I had a rare error in my Rails application. A CSS file was referring to non existing image files. And missing PNG file was somehow mapped to a controller action. Fortunately the action wasn't changing DB. This seems to be not OK that missing PNG can trigger controller action. So should I disable mod_rails for static asset directories? ...

NoMethodError in basic scaffolded View?

I created a basic scaffold for a Foo model with a single property - bar:String foos/new.html.erb: <h1>New foo</h1> <% form_for(@foo) do |f| %> <%= f.error_messages %> <p> <%= f.label :bar %><br /> <%= f.text_field :bar %> </p> <p> <%= f.submit 'Create' %> </p> <% end %> <%= link_to 'Back', foos_path %> But I ...

Rails - validates_associated with an :if condition

I am running into an issue when trying to apply an :if condition to a validates_associated validation. The if condition works for validates_presence_of, but not for validates_associated, and the form (with two models in it) works correctly, except that the validation still returns an error, regardless of whether the if condition is true ...

YAML data sequence problem

Hello, I need to have correct order of values inside Ruby array after parsing YAML file. I have this simple example showing my issue: x = "columns:\n col_1 : ~\n col_2 : ~\n col_3 : ~\n col4 : ~" s = YAML::load(x) console output gives : x = "columns:\n col_1 : ~\n col_2 : ~\n col_3 : ~\n col4 : ~" => "columns:\n col_1...

ActiveRecord counting with conditions over two tables

After watching, the latest RailsCasts with the include and joins information, I know I can do what I am doing in a much more efficient way. I have a very simple User model and a Status model. The User belongs to Status and the Status has many Users. I need to count how many users have a specific kind of status, this creates a new SQL cou...

RoutingError inside an iFrame

I scaffolded a test app and got a Routing error when I put an iFrame inside my view: This is the show template where I added the iFrame: views/bars/show.html.erb: <p> <b>Body:</b> <%=h @bar.body %> </p> <iframe src=“http://www.yahoo.com” style=“width:500px; height:500px;” frameborder=“0?></iframe> <%= link_to 'Edit', edit_bar_p...

Inline Javascript in rails partials

When writing partials in Rails I sometimes feel the urge to use inline Javascript for basic DOM manipulation functions that will only ever be relevant to the HTML in the partial. Should I feel bad about this? My thoughts are that separating out 20 lines of JS into a separate file won't save more than a few KB of bandwidth (in fact it'll...

How can I figure out how many pages are in a PDF attachment in a Rails app?

In my app a user can upload a PDF as an attachment. I want to report how many pages it has. Is there a Ruby library that would help with this? ...

Rails - Escaping HTML using the h() AND excluding specific tags.

Hello! I was wondering, and was as of yet, unable to find any answers online, how to accomplish the following. Let's say I have a string that contains the following: my_string = "Hello, I am a string." (in the preview window I see that this is actually formatting in BOLD and ITALIC instead of showing the "strong" and "i" tags) Now, I...

How do I dump a ruby on rails complex object to disk so that I can load that object into other data bases

I need to share an object (which has very complex relationships with other objects) between 2 or 3 completely separate sql databases. Ideally I'd like to have a script which is scripts/dump_object class_name object_id > file and script/load_object file. I've tried yaml_db (which dumps the whole db - which is not optimal) and it dies wi...

Multiple rubygems versions

Hi guys, Basically what I need is to install rubygems 1.3.5 on a machine (Debian) with 1.2.0 installed and having no root access. What I've done so far: installed rubygems into $HOME/rubygems and set up GEM_HOME + added bin to the path. So running "which gem" shows me the new binary, not the old one. Also when I gem install something, ...

why isn't rails (or script/console) seeing my current version of 'gem' ?

I'm having trouble getting a working rails console, and I'm not sure why. I've tried to distil my issue and the console output below sums it up : capistrano@dev:/webapps/cts/current$ ./script/console Loading development environment (Rails 2.3.4) Rails requires RubyGems >= 1.3.2 (you have 1.3.0). Please 'gem update --system' and try...

How to manage n:n relationships with Rails?

Let's say I have a Company that has many Employees and each Employee can have many Companies. Basically I will have : class Employee < ActiveRecord::Base has_and_belongs_to_many :companies end and class Company < ActiveRecord::Base has_and_belongs_to_many :employees end But then I'm confused about how I could get things like: ...

How do I associate my facebook app user with my web app user?

I have a facebook fbml app and a web application. I want my web application users to be able to add my facebook app. Seems simple, right? Currently, I am making the connection by adding a param to the canvas page link in my site. For example, I have a link that says "add our fbook application" which links to http://apps.facebook.com/o...

Find records that have children records that match all entries in a list

def DogOwner < ActiveRecord::Base has_many :dogs has_many :breeds, :through => dogs def self.with_breeds(breeds) # returns a list of DogOwner records who own all breeds in the list # ex: DogOwner.with_breeds("Dalmation","Poodle") # or it could be DogOwner.with_breed_ids(1,3) which would only require # a join down ...

Rails console scrollback

So I have two developer machines, running the same version of Rails and Ruby. One machine has scrollback functionality that survives exit and console restart. The other machine forgets everything on exit. Any idea why this is happening? How can I get a persistent scrollback buffer on my other machine? ...

How can my Rails app retrieve "www.monkey.com" from the request to display it in the view?

I need to display the "www.monkey.com" part inside some view fields. But my app runs at different addresses: "www.monkey.com" "www.hippo.com" "www.giraffe.com" How can I retrieve this name to display it in the view? ...