ruby-on-rails

Conditionally set HTML element id with HAML

I am attempting to write this html in haml so as to add an id tag if the item is the current one. This is to setup for jquery highlighting. <% if line_item == @current_item %> <tr class="line_item id="current_item"> <% else %> <tr class="line_item"> <% end %> <td><%= line_item.quantity %>&times;</td> <td><%= line_item.product.titl...

Rails find_by_sql database type dependent

So in rails I use sqlite3 for development and mysql for production. Sqlite3 and mysql handle booleans differently ("t" or "f" in sqlite3 and true or false on mysql). Usually it's not a problem when I do a find because I can do this: Comment.find(:all, :conditions => ["viewed = ?", false]) And rails will insert the appropriate value de...

heroku db:pull not working

heroku db:pull postgresql://root:@localhost/db_name After this command display this message /usr/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/abstract_response.rb:50: warning: parenthesize argument(s) for future version Loaded Taps v0.3.13 Warning: Data in the database 'postgresql://root:@localhost/db_name' will be overwrit...

rails page titles

I don't like the way rails does page titles by default (just uses the controller name), so I'm working on a new way of doing it like so: application controller: def page_title "Default Title Here" end posts controller: def page_title "Awesome Posts" end application layout: <title><%=controller.page_title%></title> It wo...

Is there find_or_create_by_ that takes a hash in Rails?

Here's some of my production code (I had to force line breaks): task = Task.find_or_create_by_username_and_timestamp_and_des \ cription_and_driver_spec_and_driver_spec_origin(username,tim \ estamp,description,driver_spec,driver_spec_origin) Yes, I'm trying to find or create a unique ActiveRecord::Base object. But in current form it's...

Rails tutorial for the dumbest person in the world (me)?

It is very difficult for me to find Rails tutorials (or books are also great) for my requirements: Stupidity Ruby 1.9 or lastest 1.8 MySQL A Game (simple roll play) JQuery front Thanks you! ...

How do I count users shirt size?

Event has_many :squads, :dependent => :destroy has_many :users, :through => :squads, :source => :squad_users Squad has_many :squad_users, :dependent => :destroy has_many :users, :through => :squad_users User has_many :squad_users has_many :squads, :through => :squad_users has_many :events, :through => :squads SquadUser belongs_...

Odd ActiveRecord behavior - behaves differently based on order of associations

I've found pretty odd behavior of rails's activerecord. This occurs in rails 2.3.9 and does not in rails 3. Here is how you can reproduce it. (Or just clone github repo example I created: git clone git://github.com/gonchs/rails-2.3.9-odd-association-behavior-example.git ) class User < ActiveRecord::Base has_one :parent has_one :con...

Options for full stack testing in Ruby on Rails

There are quite a number of options for Full-Stack testing of Rails applications. Some use real browsers, some are headless, some don't run javascript at all. Which tools do you use or recommend and why? List of browser simulators or automators: Rails built-in support for integration and functional tests (no JS) Webrat Webrat::selen...

How do I make an method for an object in rails?

Hey guys, so I have two models in my project, grinders, and votes. So each grinder has many votes, and votes belongs to grinder. The votes table has 3 columns: grinder_id:integer, choice:string, and voter_ip:string How and WHERE can I make a method for my grinders? I want to be able to do something like <% @grinders.each do |grinder...

Do has_many :through associations work for models that only exist in memory?

for class A < ActiveRecord::Base has_many :bs has_many :cs, :through => :bs end class B < ActiveRecord::Base belongs_to :a belongs_to :c end class C < ActiveRecord::Base has_many :bs end If i bring up a rails console, and do a = A.new b = a.bs.build b.c = C.new Then i get a.cs => [] but a.bs[0].c => c If a is save...

Rails Cookie detection?

Hi i'm newbie with rails amd just realized that my Rails App that i created with a beginner tutorial needs cookies to work properly, otherwise after submiting a form it gives the error ActionController::InvalidAuthenticityToken. How can i implement in an easy way a cookie detection? ...

How to change Rails 3 server default port in develoment?

On my development machine, I use port 10524. So I start my server this way : rails s -p 10524 Is there a way to change the default port to 10524 so I wouldn't have to append the port each time I start the server? ...

Emails in Rails--how to keep presentation code out of my models.

For my Rails app, we developed an half home-brewed email system. We created a model called Email which then gets added to a queue to be sent (using a web service). To create templates, we've been just mashing strings together in the model, ie: Email < ActiveRecord::Base def self.stock_message(recipient) email = Email.create do...

How to vary a helper called within a Rails 3 layout, depending on the controller

I'm using the same layout for several controllers, and inside this layout I include a menu using a call to a helper, like this: <%= side_menu %> What I'd like to do is vary the contents of side_menu depending on the controller that's invoking the layout. In an ideal world, I could define side_menu in application_controller.rb and in ...

Rails routing error after fresh install

I just installed Rails, etc. on a Windows 7 machine. Created my first app, and am trying to go to the first generated and this is what I get: Routing Error No route matches "/say/hello" Where say is the app name, and hello is the name of the first view. Thoughts? ...

Rails3 Find Wild Card Question

I'm trying to create a wildcard search, I'm doing something like this @items = Item.where("title =?", "%#{item_to_be_found}%" ...

Having trouble updating an attribute with an association attached to it

I have two models here: Package and Status Package belongs_to status Status has_many packages So, my Package model has a status_id column In my Packages controller, I've got this method (that receives data from an ajax POST call): def edit_status @status = Status.find_by_name(params[:status]) Package.update(params[:id], :status_...

Strange exception on Rails 3 caused by google bot (or something pretending to be a googlebot)

Hello everyone, Last night I got an exception on my website caused by a request with agent:googlebot. HomeController# (ActionView::MissingTemplate) "Missing template home/index with {:formats=>[:\"\\"/\\"\"], :locale=>[:en, :en], :handlers=>[:haml, :rjs, :rhtml, :builder, :rxml, :erb]} in view paths \"/disk1/home/slugs/302902_9453ada_84...

Intermittent RingNotFound error on windows

Am running a rails application which launches a series of relatively long running scripts using delayed_job and Rinda to farm out the work. At the moment am using a single delayed_job process (rake jobs:work, as am stuck on Windows), a ring server process (started with RingyDingy), and a single service process ( pretty ordinary ) The...