ruby-on-rails

Rails RESTful controllers vs. view specific controllers

This design question needs a bit of context, so please bear with me. I currently have three models that go something like this: class MyItem < ActiveRecordBase has_many :my_list_items ... class MyList < ActiveRecordBase has_many :my_list_items has_many :my_items, :through => :my_list_items ... class MyListItem < ...

Underline in Ruby Report

Hey all, I'm trying a very simple thing here in Ruport but I don't seem able to get it working. All I want is underline a part of a text. I already have the substring that I want to underline, because i thought <u></u> would do the trick (<i> and <b> work) Anybody got a working solution for this? Thanks! ...

How do I create a view that is aware of full route. (Rails 3)

How can I design my view such that it "remembers" its route? So that "Back" on /team/1/members/1 links to /team/1/members and /members/1 links back to /members? I have models of team and member. Teams have many members. My routes allow me to view all member or members on a team. resources :teams do resources :members end re...

CircularReferenceError when serializing an ActiveRecord instance (fetched by using ThinkingSphinx) to JSON

I try to serialize an instance of my ActiveRecord model to JSON (using "render :json => @entities" or "@entities.to_json"), but I always get an CircularReferenceError ("ActiveSupport::JSON::Encoding::CircularReferenceError (object references itself)"). This only happens when the ActiveRecord instances are queried by using ThinkingSphinx....

money representation in mongoid

How should I work with Money with MongoID? Should I configure it as BigDecimal? And at rails level? For ActiveRecord we have something called Money, but AFAIK it just supports AR ...

Capistrano does not copy Gemfile using SVN

Gemfile is checked in the repo and from the server I am able to checkout the Rails application with the Gemfile in the right place (Rails.root). When I run 'cap deploy' Capistrano copies everything except the Gemfile, so I get the Bundler error 'Could not locate Gemfile'. Whey with SVN I am able to checkout Gemfile and Capistrano is not?...

Checking an attribute is true before executing a CRUD action

Before any of my article controller crud actions can run (excluding index), i want to make sure that the article's active field is true. I thought about doing this in a before_filter, but at that point @article has not been set, any ideas please? Thanks ...

Can I use Capistrano from a windows dev setup to deploy to a Linux server?

Can I use Capistrano from a windows dev machine to deploy to a Linux server? This is for a rails app. ...

How can I get SQL statement created by ActiveRecord#find without actually executing it?

I am using will_paginate with some complicated queries and it is unable to correctly calculate number of total records (in order to display proper number of page links) - namely because of grouping by multiple columns. So, I am intending to get the SELECT query which would be used to retrieve ALL records, without actually executing it, ...

Tracking unique visitors in Rails app - session or explicit cookie?

Hi, So here is the situation - I have a store app that I want to ultimately calculate the number of unique visitors to number of orders placed each day (basic conversion percentage). I am debating whether or not to store a visitor_id in Rails session or setting an explicit cookie on client. Either way, both would check to see if a visit...

Rails: rake db:migrate isn't output to script/server console window

i have two cmd consoles opened in Windows. One is running the "ruby script/server" the other i run a "rake db:migrate" command. But the server console doesn't output the log of the migration? Someone has an idea what's the reason? ...

Web page that links all files in a directory

As the title says, I want to build a ruby web page that dynamically links all files in a directory. Does anyone have any sample code or basic suggestions as to how to do it? Thanks in advance for your help! ...

Does rake db:schema:dump recreate schema.rb from migrations or the database itself?

Does rake db:schema:dump recreate schema.rb from migrations or the database itself? thanks ...

Rails Associations Help

I have a Users model which has many Projects. But each Project are of different types. A WebApplication, DesktopApplication and so on. All these different types have their own specific fields and yet they share common fields which will be stored in the Projects table. I have thought of this solution having multiple has_one to each of t...

Average Postgres Column when column is String? (Cast as Integer)

I am using ActiveRecord and want to average a generic table column that's typed as a string (char), but holds numbers: | key | value | | "square_footage" | "142555" | How do I write this so Postgres doesn't give me this error: PGError: ERROR: function avg(character varying) does not exist LINE 1: SELECT avg("settings".value) AS ...

Reusing form nested and not nested, how to show submit button

I'm learning rails and building a recipe app. In my app, a Recipe has a bunch of ingredients. I've got my ingredients form nested within my recipe form, and I call it with a partial. Of course, because the form is nested, the <%= f.submit %> is in the recipes/_form.html.erb page. So now I'm trying to edit a single ingredient outside...

multiple paperclip attachements with watermark processor

Hi guys! I'm having a ton of trouble with uploading multiple attachments with paperclip and processing them with a watermark. I have 2 models, Ad and Photo. The Ad has_many :photos and the Photo belongs_to :ad. To be more exact in /models/ad.rb I have: class Ad < ActiveRecord::Base has_many :photos, :dependent => :destroy accep...

How to add aditional rest routes to a nested resource in rails

I have a widget that has many links. In the routes file: map.resources :widgets, :has_many => [:links] I want to add a "sort" action to links. What do I need to add to the routes file, so I can write sort_widget_links_path(widget) Thanks, Deb ...

ruby twitter api :uninitialized constant Twitter::HTTPAuth (NameError)

require 'rubygems' require 'twitter' httpauth = Twitter::HTTPAuth.new('myusername', 'mypassword') client = Twitter::Base.new(httpauth) It is throwing : uninitialized constant Twitter::HTTPAuth (NameError) i have "twitter" in my gem list, i dotn understand where is the problem ...

rails polymorphic url params

I like polymorphic style url very much, so I can write link_to 'New taste', [:new, :taste] instead of link_to 'New taste', new_taste_path But is it possible to add query parameters to first one without using polymorphic_url/polymorphic_path? ...