ruby-on-rails

When to use a lambda in rails?

When should a lambda or proc be used? I have seen them described as anonymous functions, but I am struggling to understand this concept. I would appreciate any links to or examples of when you might use one in ruby, but especially in rails. Thanks ...

Rails counter cache vs calculation

I have a collection which I want to show totals for, and the idea was to use a cache for each of the totals I need. However I also will need to drill down into the data set. So most likely I will have to load the collection anyway. So should I still use the cache or just use a calculation? ...

Very strange problem with Gettext and Haml on Rails / rake updatepo broke

Hi, I'm on Rails 2.3.3 and using Haml 2.0.9 for my templates and Gettext-Rails 2.0.4 for the translation. Haml works like a charm and gettext is also working like it should. But I cant get Gettext to parse Haml Files when using "rake updatepo". I created a custom parser like this: # lib/haml_parser.rb require 'gettext_rails/tools' req...

versioning has_many_polymorphs associations

I've done a research on rails versioning support and found plugins like acts_as_versioned, acts_as_versioned_association (this one have a really serious lack of documentation), simply_versioned and acts_subversive. Some of these support versioning of associations but haven't power enough to go smoothly with polymorphics ones. I'm wonde...

Protecting Content with AuthLogic

I know this sounds like a really, really simple use case and I'm hoping that it is, but I swear I've looked all over the place and haven't found any mention of any way - not even the best way - of doing this. I'm brand-spanking new to Ruby, Rails and everything surrounding either (which may explain a lot). The dummy app that I'm using a...

form_for Nested Resources

Here is the route: map.resources :networks do |network| network.resources :channels, :name_prefix => nil end Here is what I have in my for my form. <% form_for ([@network, @channel]) do |f| %> ... <% end %> I get an undefined method error since form_for is trying to call "network_channel_path". This error occurs because I h...

get a list of all models from rails

Hi I need a list with all models (class_names) which have the pattern "Cube" at the end. example: all my models: ModelFoo, ModelBar, ModelBarCube, Mode2BarCube what I need: ['ModelBarCube', 'Mode2BarCube'] ...

Send form data to HTTPService: how to approach it in Cairngorm?

The form is in a component lauched as a popUp, form data consists in: login:String password:String I thought of a few different ways, but I don't like them.. in the popUp, send button triggers a function that gets the form values and stores them in an Object, then saves the Object in the model, then dispatches a CreateSessionEvent. ...

rails helper for select_tag?

I don't get the point how can I do that code with an select helper? <% @cube_names.each do |cube| %> " <% if @cube_name == cube %> selected="selected"<% end %>><%= cube %> <% end %> I have a list (@cube_names) and want a HTML select box width all values of the list and the default value (param @cube_name) sh...

rails + attachment_fu: issue with files in directories

Hi, I use attachment_fu for my rails app. It's great for me. However, the designer who works with me complains about it because it saves files in different directory. She said that she can't handle those files efficiently with Photoshop as they are scattered. I tried to persuade her with the following reasons. We can avoid file name...

Rails destroy confirm with Jquery AJAX

I have got this working for the most part. My rails link is: <%= link_to(image_tag('/images/bin.png', :alt => 'Remove'), @business, :class => 'delete', :confirm => 'Are you sure?', :id => 'trash') %> :class => "delete" is calling an ajax function so that it is deleted and the page isn't refreshed that works great. But because the page...

Rails : Rake Test:functionals cannot access DB (Sqlite3 on winXP)

Hi, I am unable to run rake test:functionals with SQLite3, it gives me this error : rake aborted! Permission denied - db/test.sqlite (See full trace by running task with --trace) My setup is on Windows XP. Tests were working a few weeks ago. Rails 2.3.2, Rake 0.8.7, sqlite3-ruby 1.2.5 gems I am using Netbeans for development, but e...

Rails "undefined local variable or method" for an attr that isn't even refrenced

I'm at a loss here. When running in Dev mode (script/server) I the error "undefined local variable or method 'id' for #<InsertModelNameHere:0x7f19bdb87dc8>" at random times when I try to list entries for a number of my models. If I refresh the page it works fine and I'm assuming that I only see it in dev because everything gets reloaded...

Data Modeling Question for Rails

I have the following entities. User Event Expense Guest A User is someone that is registered with my site. An event is something that a specific user can create and then invite people to (other users). An expense is created by a specific user for a specific event and can be associated with other users/guests of the event (like us...

Integration testing with Authlogic?

For the life of me I don't understand why Authlogic isn't logging me in in this integration test. I haven't had any problems w/ Authlogic logging me in in functional tests using this code. According to the authlogic rdocs (http://tinyurl.com/mb2fp2), simulating a logged-in state is the same in functional & integration tests, so i'm pret...

Creating forms for relational data in Rails

I have a form that I need to display for a table that has a relationship with a couple of other tables. For instance, I have a table "cases" (think, investigator case), that has_one claimant and has_one client. I would like the form to display the fields to fill out for the case data, client data and claimant data. Is there an easy ...

Fastest way to search two models connected via join table in rails given large data set

I have a user model and a cd model connected through a join table 'cds_users'. I'm trying to return a hash of users plus each cd they have in common with the original user. @user.users_with_similar_cds(1,4,5) # => {:bob => [4], :tim => [1,5]} Is there a better/faster way of doing this without looping so much? Maybe a more direct way?...

Optional path prefix persistence, using Sven Fuchs' routing filter

I made my routes recognize optional path prefixes, but now I want route generation to remember them without me specifying them each time. I'm using the solution presented here: http://stackoverflow.com/questions/212425/creating-routes-with-an-optional-path-prefix Here are some examples: Let's say I'm here: { path => "/", :contoller =...

Deploy a Rails app on Dreamhost

I am trying to deploy my first Rails app. I copied all files to ~/mysite.com and set up MySql. Here's my configuration at Dreamhost. Now when I visit mysite.com I get a 404 error (which isn't my custom 404 error). It seems that Passenger does not run! What should I do? Do I need to start Passenger? (touch tmp/restart.txt does nothing)...

What does has_many_polymorphs mean by "Referential integrity violation"?

I have a has_many_polymorphs relationship between a Candidate and many events of various type. In particular, a Candidate creates a Created event when it is created. class Candidate < ActiveRecord::Base has_many_polymorphs :events, :through => :candidate_events, :from => Event::Base.included_in_classes.m...