ruby-on-rails

Validation not bubbling up to my other models.

Ok, I have a relationship between People, Users and Employees such that All Employees are Users and all Users are People. Person is an abstract class that User is derived from and Employee is derived from that. Now... I have an EmployeesController class and the create method looks like this: def create @employee = Employee.new(params...

Authlogic Multiple Password Validation

Hello, I'm using Authlogic to manage my user sessions. I'm using the LDAP add-on, so I have the following in my users model acts_as_authentic do |c| c.validate_password_field = false end The problem is that recently I found out that there will be some users inside the application that won't be part of the LDAP (and can't be a...

Yaml::load_file acting different between development and production (Rails)

Hi, I am completely stumped at the nature of this problem. We export data from our application into a 'cleaned' YAML file (stripping out IDs, created_at etc). Then we (will) allow users to import these files back into the application - it is the import that is completely bugging me out. In development, YAML::load_file(params[:uploaded...

Rails activerecord attributes=

Hi, I am doing this: @person.attributes = params[:person] Can anyone give me a clue as to why doing an attributes= would cause a bunch of SQL to show in my logs? I see a couple of SELECT and even an UPDATE. I swear I am not doing a "save" -- so I have no idea why setting attributes would trigger queries. Is there a before_ of af...

Rails: how to prevent links from being clicked while swf flash file is displayed

Hi everybody, I'm looking for a good way on preventing links in my rails app having any effect while a swf file is active... Can I do this with a before_filter? Or do I need javascript? Markus ...

Loop each x elements

What's the beste way to show a list with 20 images in rows of 5? Or, in other words, how do I clean up this ugly snippet? <div class="row"> <% @images.each_with_index do |image, index| %> <% if index != 0 && index % 5 == 0 %> </div><div class="row"> <% end %> <%= image_tag image.url %> <% end %> </div> ...

Rails testing with factories. Transactional uniqueness problem.

I keep getting validation errors when running factories due to uniqueness constraints on fields. I am using shoulda with factory_girl. I have a both a unit test and a functional test creating 2 products in the database. I can run 'rake test:units' and 'rake test:functionals' over and over in any order and everything is will be green b...

Simple way to specify sidebar in the controller

Hello, I'm wrestling with something that should be very simple - specify a sidebar at the controller level. With layouts you can do this: layout 'admin' so I'd like to do the same for a sidebar, with something like this: sidebar 'search' I know I could specify the sidebar markup with content_for in the views, but I'd rather specif...

Why do I need to use .inject(0) rather than .inject to make this work?

I am creating a rails app and have used this code in one of my methods item_numbers.inject(0) {|sum, i| sum + i.amount} item_numbers is an array of objects from my item_numbers table. The .amount method that I apply to them looks up the value of an item_number in a separate table and returns it as a BigDecimal object. Obviously the in...

Rails - how to code 'may belong to?'

I'm working on a Rails app that will contain information on a bunch of people. There are two use cases: An administrator enters and maintains a person's profile The person can decide to sign up, log in, and maintain their own profile I'm trying to work out the relationship between the profile and the user. Right now, it's that profil...

Search Issue by using sphinx in ROR project

Hello everyone: I have a ROR Project with db structure like this: class Business has_many :business_categories, :include => :business, :conditions => ["businesses.version = business_categories.version"] has_many :categories, :through => :business_categories, :source => :category end class Category has_many :business_cate...

Ruby open_id_authentication with Google OpenID

I am in my first steps of implementing OpenID in my Rails app. open_id_authentication appeared to be a fairly easy-to-use plugin, which is why I decided to use it. Logging in with my Google account seems to work perfectly, however I do not get the sreg/AX fields that I require. My code is currently as follows: class SessionsController ...

how to work with attachment-fu in 100mb size zip file?

I am uploading 100 mb file in attachment-fu , i have given size also upto 128mb in the model file too. But when i attach zip file, the files started repeating by it self ,and if i upload same 20mb file it works perfaclty fine. And if i do this process on the server it takes so much process and load too, is there any way to solve thsi ? ...

Unable to reverse seemingly simple rails migration - getting "altered_table.column may not be NULL" error

I have a table 'invoices' in my development database (sqlite3) populated with a small amount of test data. I wanted to add a column 'invoice_number' to it and set up a migration like so: class AddInvoiceNumberColumnToInvoices < ActiveRecord::Migration def self.up add_column :invoices, :invoice_number, :integer end def self.d...

How can I test ActiveRecord::RecordNotFound in my rails app?

Hi, I have this code in my controller and want to test this code line with a functional test. raise ActiveRecord::RecordNotFound if @post.nil? which assert method should I use? I use the built-in rails 2.3.5 test framework. I tried it with this code: test "should return 404 if page doesn't exist." do get :show, :url => ["noth...

Ruby: watching method (re)definition in runtime

I'm looking for a way (library or metaprogramming trick) to hook into method definition, so that I could extend certain classes and catch their method (re)definition "events". ...

authlogic in Rails

Hello, I am using the authlogic gem for authentication. I have followed the steps at: http://railscasts.com/episodes/160-authlogic I have the following code: # config/environment.rb config.gem "authlogic" # models/user.rb acts_as_authentic # users_controller.rb def create @user = User.new(params[:user]) if @user.save flash[:...

How do I pass ImageMagick environment variables to nginx mongrels?

My Rails app makes use of ImageMagick, but the app fails on trying to execute the ImageMagick command ("identify"). I fixed this issue in development (where I'm running Apache/Passenger) by passing the following environment variables in my Apache config: SetEnv MAGICK_HOME /opt/local/var/macports/software/ImageMagick/6.5.9-0_0+q16 S...

ActionView::TemplateError (integer 23656121084180 too big to convert to `unsigned int')

Hi, this is the weirdest error I've ever got on Rails. Any idea what this may be is? NOTE: the error DOES NOT come from @order.get_invoice_number, I've tried to separate the code into multiple lines and it was clear the problem is within {:host... } ActionView::TemplateError (integer 23656121084180 too big to convert to `unsigned i...

rails: has_many :through validation?

Rails 2.1.0 (Cannot upgrade for now due to several constraints) I am trying to achieve this. Any hints? A project has many users through join model A user has many projects through join model Admin class inherits User class. It also has some Admin specific stuff. Admin like inheritance for Supervisor and Operator Project has one Admin,...