ruby-on-rails

Saving updates to objects in rails

I'm trying to update one of my objects in my rails app and the changes just don't stick. There are no errors, and stepping through with the debugger just reveals that it thinks everything is updating. Anyway, here is the code in question... qm = QuestionMembership.find(:first, :conditions => ["question_id = ? AND form_id = ?", q_id,...

Singular or plural controller and helper names in Rails

Is there any disadvantage to using singular names for controllers and helpers? Nothing seems to rely on this. It even seems helpers don't have to make the same choice about singular vs. plural as their corresponding controllers, at least according to my limited experimentation. Is that true? ...

Why does new Rails db migration file start with datestamp instead of sequence number?

Whenever I use script/generate to generate a new scaffold for a change to my Rails database, the new migration file is prepended by a datestamp (e.g. 200903140912_create_users.rb) instead of a sequence number (e.g. 004_create_users.rb). I then have to manually change the file name to fit in with the rest of the migration files. Does an...

How to use in_place_editing instead of fields_for?

I setup a User model with restful_authentication and then have a Profile model that belongs to it. I've been using fields_for to combine the fields for editing a User and that user's profile into the User edit view. I'd like to be able to set a few of the fields to use the in_place_editing plugin on the User show view. It works fine on ...

Error installing Rails 2.3 RC2

I'm trying to install rails using the following command: $ sudo gem install rails --source http://gems.rubyonrails.org But this is what i'm getting: WARNING: RubyGems 1.2+ index not found for: http://gems.rubyonrails.org/ RubyGems will revert to legacy indexes degrading performance. ERROR: While executing gem ... (Gem::Pac...

Ruby/Rails thread safety

I have been hacking with Ruby from time to time, but I haven't done anything big or multithreaded with it. I have heard that MRI only supports green threads and JRuby supports native threads via JVM. However, I stumble upon comments on blogs and discussion groups which say that "Rails is not thread-safe" or that Ruby itself is not thread...

RSpec should redirect_to problem

Hi, I'm writing a spec for my Rails controller, this is the action I'm testing: def create @course = Course.new(params[:course]) if @course.save then #flash[:notice] = 'Course Created' redirect_to courses_path else render :action => 'new', :status => 400 end end And this is the spec that validates it: describe "PO...

Nokogiri: Searching for <div> using XPath.

I use Nokogiri (Rubygem) css search to look for certain <div> inside my html. It looks like Nokogiri's css search doesn't like regex. I would like to switch to Nokogiri's xpath search as this seems to support regex in search strings. How do I implement the (pseudo) css search mentioned below in an xpath search? require 'rubygems' requi...

Rails: How do I find() all records unique in certain fields?

I have a list of 'request' objects, each of which has fairly normal activerecord qualities. The requests table is related to the games table with a join table, 'games_requests,' so that a request has a request.games array. The question is, is there a way to do a find for the last n unique requests, where uniqueness is defined by the ga...

Rails with Non-Rails Database Design

Complete newbie researching Rails. Can Rails be used with a read-only schema that doesn't conform to the Rails' default naming and design conventions? For example, my database's schema has base tables that use string columns for unique primary keys. For example, a base table called Jobs, might have a unique primary key defined as Jo...

How to determine which controller an action belongs in?

I have two models: releases have many elements, and elements belong to releases. The action I wish to define imports all elements (making copies of them all) from one release into another release. How do I determine if this action belongs as a member action on the releases controller, or a collection action on the elements controller?...

Broken foreign keys in Rails

So here's a quick question. I'm using Rails with a huge legacy database, and it has many broken foreign keys that need to be treated as nils. So when I do: Foo.find(:all, :conditions => {...}, :include => :bar) Rails with connect all bars with SELECT * FROM bars WHERE id IN (...). So far so good, just two sql queries. Now the problem ...

Rails: Searching multiple tables from one query

How do I write condition statement in find or paginate method to allow users search in Project and Project Category names simultaneously? Now my code looks like this @projects = Project.paginate :per_page => 20, :page => params[:page], :conditions => ['name LIKE ?', "%#{params[:search]}%"] So I have also Category table with name fiel...

Using the session variable in my view

I've been told that I shouldn't use variables such as params[:user_id] in my view files. Does the same rule apply to the session variable? If not, then what should I be doing? Assign it to an instance variable first and then use that in the view? This seems annoying as I would have to do it for each of my actions. I guess I could put t...

Rails: Script to import data

I have a couple of scripts that generate & gather large amounts of data that I will need both to seed my database with and in the future to add large amounts more to it. What is the best way to import lots of relational data into a rails database as both seed data and intermittently during production? I haven't settled on an output for...

What's the best way to integrate Rails Restful Auth App Login into Wiki (MediaWiki?)

I have a ruby on rails app using restful authentication and I'm looking to add a Wiki to my site. MediaWiki looks like my best option since it's full featured and I can work with the LAMP stack. However, I'm not sold on MediaWiki if there's another (preferably open source) app that will integrate better. I would like to know if anyone...

Where are the downloadable Rails generators?

When I run... $ script/generate I get a list of installed generators and a message saying "More are available at http://wiki.rubyonrails.org/rails/pages/AvailableGenerators." However, the indicated wiki page says "This topic does not exist yet." Does there exist some central repository of downloadable Rails generators? In particular...

Help with 'Missing these required gems: error'

I get this error with gems that I install from github. I am on a XP machine. This time I installed, giraffesoft-is_taggable gem. gem list says it's there. I created a sample rails app and added config.gem "giraffesoft-is_taggable" to the environment.rb file. Start the app and I get the error: Missing these required gems: giraff...

Best rails solution for a mailer that runs every minute

Hello, I have an application that checks a database every minute for any emails that are supposed to be sent out at that time. I was thinking about making this a rake task that would be run by a cron job every minute. Would there be a better solution to this? From what I have read, this isn't ideal because rake has to load the entire ra...

Nokogiri: Navigating the DOM.

I'm trying to fill the variables parent_element_h1 and parent_element_h2. Can anyone help me use the Nokogiri Gem to get the information I need into those variables? require 'rubygems' require 'nokogiri' value = Nokogiri::HTML.parse(<<-HTML_END) "<html> <body> <p id='para-1'>A</p> <div class='block' id='X1'> ...