ruby-on-rails

How to fix the Rails text helper 'truncate' after upgrading to Snow Leopard?

I just upgraded to Snow Leopard and went to edit some code on a legacy Rails app (1.2.5) and found that the views cause a crash when trying to render the 'truncate' text helper. I took them out and it rendered fine. How do you fix this? Are there other methods that might see the same issue? ...

Updating join table field

class Job < ActiveRecord::Base has_many :employments, :dependent => :destroy has_many :users, :through => :employments class User < ActiveRecord::Base has_many :employments has_many :jobs, :through => :employments class Employment < ActiveRecord::Base belongs_to :job belongs_to :user # Employment has an extra attribute of confirm...

How to get current context name of rspec?

if i have rspec like this describe 'Foo' do // init go here describe 'Sub-Foo' do it "should Bar" do // test go here // puts ... <-- need "Foo.Sub-Foo should Bar" here end end end How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here? It is similar to format with spe...

Problem with request.request_uri when forwarding from AJAX partial - Rails

Hi, In my Rails logging in functionality I use session[:return_to] = request.request_uri and then in the logging functionality I use: redirect_to session[:return_to] Which works fine except when I render a partial with AJAX. What happens is that the request.uri is for the AJAX request which screws up and doesn't render what's exp...

What are some good approaches for outsourcing Rails work?

Hi all, It seems that a great way to build an app might be to identify all the horizontal / domain-independent pieces that don't already exist in the form of gems, plugins or engines, and commission an outsourcing firm to build those pieces in complete isolation from the rest of the code base. So let's assume a plugin is a great way. ...

Dynamic Rails routing based on database

Hello, I'm building a CMS with various modules (blog, calendar, etc.) using Rails 2.3. Each module is handled by a different controller and that works just fine. The only problem I have is with the root URL. Depending on the configuration chosen by the user, this default URL should show a different module i.e. a different controller, b...

rails has_many - too many queries

I have 4 models, Message, Group, User, Membership class Group < ActiveRecord::Base has_many :memberships has_many :users, :through => :memberships has_many :groups_messages has_many :messages, :through => :groups_messages, :order => "created_at desc" named_scope :with_memberships, :include => :memberships end class Membersh...

Running a single validation in Rails

Hi, I'm sending friends invitations and I want to validate email address using User.validates_format_of :email, except that User.email has a couple of other validations which I'm not really interested in. So is there a way to run a single validation on a model or check if that specific validation has passed (without doing user.errors...

Extend model in plugin with "has_many" using a module

I have a some code in an engine style plugin which includes some models. In my app I want to extend one of these models. I have managed to add both instance and class methods to the model in question by including a module from within an initializer. However I cannot seem to add associations, callbacks etc. I get a 'method not found' er...

Manually instantiate ActiveRecord models and their relationships?

If I have T-SQL (or a stored proc) that returns records from multiple tables (using DBI perhaps), is there a way for me to manually instantiate the ActiveRecord models and their associations? Obviously, I’m after database performance here. I would like to be able to build my own object hierarchy (models and their relationships), but wh...

uninitialized constant Test::Unit::TestResult::TestResultFailureSupport

I get the error in subj when I'm trying to run specs or generators in a fresh rails project. This happens when I add shoulda to the mix. I added the following in the config/environment.rb: config.gem 'rspec', :version => '1.2.6', :lib => false config.gem 'rspec-rails', :version => '1.2.6', :lib => false config.gem "thoughtbot-shoulda"...

Matching available languages to language names

I want to make a language selection dropdown in a site user edit/create page. For this purpose, I have of course translated the site to more than one language. Using I18n.available_languages, I can then get an array of locale codes, like so development environment (Rails 2.3.4) > I18n.available_locales => [:en, :da] Furthermore, I...

DRYing up routes and javascript responses

Hi, I'm not sure if I'm missing a known design pattern, but I keep coming up against the following problem with RESTful routes Rails. In my example, I have a users controller that can respond in javascript (:js) format. The default response populates a page element with a list of the paginated users: # /app/controllers/users_controlle...

Resource mapping works locally but not on webserver

Edit: Well maybe this can give a clue. When created a Rails app in cPanel on my web host, in order to access the app you need to create a rewrite rule. Which I did, but didn't know what it did. I tracked it down to it creating the following 2 files: home/mydomain/public_html/.htaccess: RewriteEngine on RewriteCond %{HTTP_HOST} ^mydoma...

Incompatibily between ruby and mysql gem

When trying to install the mysql gem from cPanel on my website, I get an error saying that the gem requires Ruby >= 1.8.6. This is a shared server and the version of Ruby is 1.8.5 and can't be upgraded. I do not have shell access and it seems the only way for me to install a gem is through the list of gems within cPanel. How can I get m...

First 10 items in a many-to-many relationship in RoR

I have a database with two tables: tags and items. Each Item has a score, the highest scoring items being the most popular. There is a many-to-many relationship between tags and items. Getting all items belonging to a tag is easy. (= tag.items) But how do I retrieve the 10 most popular items belonging to this tag? So in fact I need th...

How to add another column to the issues table report in redmine?

I would like to know if someone can help me to determine what steps I do need to modify redmine in the table shown at the url http://0.0.0.0:3000/projects/my_project/issues I need to add another column, lets say "close date", where it reports the last date on which an issue became closed state. as I understand redmine, the matter is ...

Rails Complex Form Validations ?

I have a complex form for my Work model. It accepts nested attributes for Credits, Images and Videos. (it is a modified version of Eloy Duran's complex form example) I want to validate presence of at least one Credit I want to validate presence of at least one Image or one Video When I do (in work.rb): validates_presence_of :credits...

Calling Rails update Method via Inline Edit

I was putting together a quick inline editing feature in my first Rails app and just as I was getting it working it occurred to me that I may be violating RESTful principles. The edit updated an image name. To do so, it submits, via PUT to Image#update and passes the new modified name as image[name]. The database gets updated properly,...

In Rails, how to calculate a value based on a set of child records and store it in the parent record

I have invoices that are made up invoice items. Each item has a profit and I want to sum these up and store the total profit at the invoice level. Previously I was doing this calculation on-the-fly, but to improve performance I now need to store this value in the database. class InvoiceItem < ActiveRecord::Base belongs_to :invoice en...