ruby-on-rails

Rails: Best practice for model dependency class locations?

I have a rails app moving along fairly well, but the fact that I'm doing this myself means that some poor sod is eventually going to see this and say, "What the hell were you thinking? Why did you put this here?!?!" Where is that poor, sorry soul going to expect to see a series of classes that aren't used by anything but a single model...

Rails ActiveRecord: Automatically Alias/Append Suffix?

I've got a legacy database with a bunch of idiotically named columns like: some_field_c some_other_field_c a_third_field_c I would very much like to make a Rails ActiveRecord sub-class that automatically aliases these attributes to their name minus the underscore and "c". However, when I tried: attributes.each_key do | key | name =...

Better Performance on Associations

Right now I have a table called Campaigns that has many Hits, if I call say: Campaign.find(30).hits Which takes 4 seconds, or 4213 ms. If I call this instead: campaign = Campaign.find(30) campaign.hits.count Does it still load all of the hits, then count? Or does it see I am counting and avoids loading all of the hits? (Which is cur...

Rails fixtures -- how do you set foreign keys?

I'm reading about Rails fixtures in this guide (thanks, trevorturk). It appears you define classes in a Yaml file and they're automatically loaded into the test DB -- cool. But if you want to specify that this recipe belongs to that cookbook (or whatever) how do you do that? Are you supposed to specify the values for cookbook.id and re...

Availability of ROR flash functionality in ASP.Net-mvc

Does Microsoft MVC make available a mechanism comparable to RubyOnRails internal storage container known as flash? The preference would be not using UpdatePanel tricks. ...

Handing Non-UTF8 content in my Rails application appropriately

I have a Rails application that allows users to import information from various sources using RSS feeds and such. My default encoding on the database is UTF8 and I've been receiving a lot of exceptions in regards to non-UTF8 data that is coming through the system and crashing once it hits the database. I'm to appropriately detect the n...

Rails : Retrieved Object has no attributes, and is not comparable with real

This issue is really losing me. I have a model for authentication : user. I have a model for comments : comment. I have a model that is commentable : weburl. Weburl 1..* Comment Weburl *..1 User Comment *..1 User The issue I have is not testable (my tests are all passing), and does not happen all the time. Usually it happens the sec...

How do I delete an OU with everything inside at once?

I would like to have a single LDAP command that would delete an entire OU atomically, including all children. I see there's a command for the windows command-line: Delete an Organizational Unit dsrm <OrganizationalUnitDN> [-subtree] That -subtree option deletes children too. Is there a way to do that using LDAP? Bonus points, if som...

Modifying the behavior of link_to in a Redmine installation (ruby on rails)

I'm trying to modify the UI of a Redmine installation (Redmine 0.7.3.devel.2093 (MySQL)). When you view a project in Redmine, it generates a list of all the subprojects for the project. For example, app/views/projects/index.rhtml calls the link_to function: <% if @project_tree[project].any? %> <p><%= l(:label_subproject_plural)...

Has anyone written a plugin to add the final polish to ActiveResource?

I have been using ActiveResource in my Ruby on Rails applications for some time, and I am starting to really feel that it needs a final polish to make it go from "pretty nice" to "beautiful". I would like to be able to use an ActiveResource as if it were an ActiveRecord. If I could use has\_many, belongs\_to and other niceties with Act...

"rails" command on windows

So I installed Ruby On Rails using the Windows Installer. Now the startup guides says I have to start up an Terminal and run the Rails command to make a project. I don't have a terminal, so how do I execute a Rails command and make a project?? The CMD command line in Windows does not recognize "rails" I don't think it is an PATH probl...

Performance implications of using BigDecimal vs. Integer in a Rails app

How much less efficient would it be to store some fields as a BigDecimal instead of as an Integer in a Rails app? Some computation (a bunch of arithmetic) will be done with these values. Does this affect performance for Rails, the database or Ruby in general? ...

Rails: ruby script/generate model, where are the docs?

I am running ruby script/generate scaffold or ruby script/generate model and I know the basic syntax, like ruby script/generate scaffold Dude name:string face:boolean but I do not know things like: should names of variables have underscores or be camelCased? what kind of variable types are acceptable? Where can I find such...

How can I do AJAX-y conditional show/hide form fields in Rails?

I'd like to show or hide a few fields in a form in Rails, depending on the state of a select field in the form. I don't (currently) need a second database lookup for the fields, so I'm trying to keep it all confined to the view. I have the outline sketched out, but I'm having some trouble with the implementation details. My initial tho...

Use RJS code in the onclick event of a button

Hi all, I know how to add javascript code to an onclick event of a button eg: <%= submit_tag 'Enter', :onclick => "this.disabled=true,this.form.submit();" %> I wonder if I can use rjs in the onclick. I want to use it to render out a partial. Thanks, Stijn ...

Sql Server (Entity Framework): created_at , updated_at Columns

I think I should mention I'm trying to get Entity Framework\SQL server to do something that I was used to coming from Rails. I really just want to know the 'best' way to have automatic created_at & updated_at column values for records that I insert/update in the database. Right now I've hooked into the ObjectContext.SavingChanges event...

Is there a way to get a collection of all the Models in your Rails app?

Is there a way that you can get a collection of all of the Models in your Rails app? Basically, can I do the likes of: - Models.each do |model| puts model.class.name end Thanks in advance. ...

Is there a bulk email plugin for Rails apps?

Does anyone know of a plugin or something that can be used to send bulk emails for a Rails app? Specifically, I'd like to be able to pass an HTML email file to a rake task or something and have it emailed out to everyone who has signed up to my site and checked the "please send me info about XXX" box. I wrote kind of a hacked-together ...

What's the best resource for learning Rails for a raw beginner?

I want to tell someone what to look at to learn Ruby and Rails. He knows PHP and is a smart guy. For Ruby, I recommended David Black's Ruby for Rails, warning him that the Rails chapters are outdated. What do I recommend for Rails? Perhaps the "beta book" version of AWDR, third edition? I'm wondering whether it's close to being a comp...

id field without autoincrement option in migration

I have a DB migration like so: class CreateParticipations < ActiveRecord::Migration def self.up create_table(:participations, :primary_key => 'Seat') do |t| t.integer :Seat t.string :Nickname t.string :Clan t.string :FirstName t.string :LastName t.string :...