ruby-on-rails

Ruby soap4r build headers

Hi, Again with the soap. I am trying to build a header using soap4r that is supposed to look like this <SOAP-ENV:Header> <ns1:UserAuthentication SOAP-ENV:mustUnderstand="1" SOAP-ENV:actor="http://api.affiliatewindow.com"&gt; <ns1:iId>*****</ns1:iId> <ns1:sPassword>*****</ns1:sPassword> <ns1:sType>affiliate</ ns1:sType> </...

Nested Through Has Many Associations

Hey folks, I am having some trouble creating a nested association and I can't quite spot what's going on: class Package < ActiveRecord::Base has_many :selections, :class_name => "PackageSelection" has_many :channels, :through => :selections has_many :categories, :through => :channels, :source => ????? end class Channel < ActiveR...

How to get the 'th' and 'rd' on a date?

strftime('%A, %B %d') Will output Monday, August 31 Any way to get it to do Monday, August 31st? ...

Hoptoad v. Exceptional v. exception_notification v. exception_logger

Which of the following exception notification solutions is the best? Exceptional Hoptoad exception_notification exception_logger ...

Multiple many_to_many relationships

Multiple many_to_many relationships - Admin functionality I have a composer has_many[collections, categories, styles] A composer's membership in a collection, categories, styles is updated the through a page of checkboxes for each has_many So should I have my own custom restful routes/methods, such as update_collections, update_catego...

set instance variables with activescaffold

Hi All, I've recently added activescaffold to an existing rails project, and the problem I'm having is that the variable names that activescaffold is using are not the same as the ones I already have. Rather than go through my entire application and change all of the instance variable names, I'd like to be able to set the instance varia...

One input box, many possibilities...in Rails

I have an input box which I want to handle two types of information, foo and bar. The form action is set to either the foo controller or 'bar controller. It really doesn't matter which one. For the sake of example, the form action is to foo/new. In the controller, I have a function that looks at the form input text and determines if i...

ruby session variables

I'm trying to write basic assert test: def assert_session_has ( sessionvar ) return assert_not_nil session[:sessionvar] end when I compile: def test_auth_bob #some setup and other validation methods assert_not_nil session[user] #more validations... end I get the following error: test_auth_bob(UserControllerTest): N...

Rails find won't join when args appended...

I'm hoping I'm doing something wrong here and someone can point me in the right direction... I have written a method inside of one of my models, here is the code: def self.find_by_user_id(user_id, *args) self.find(:all, :joins => :case_map, :conditions => ['case_maps.uer_id = ? and case_maps.case_id = cases.id', user_id], ...

MySQL Gem, Ubuntu & UTF8

I have a web-app that was done in Rails 1.2.3 and I have just migrated it to rails 2.2.2 and upon deploy the app broke. It turns out I needed to install the MySQL gem since rails 2.2.2 needs this. So, I did install it but I had to install with "sudo gem install mysql -- -with-mysql-config" (as per http://brantinteractive.com/2007/02/16...

How to create MD5 hash with HMAC module in Ruby?

Hi all, Using Google + Bing didn't yield an answer to what should be a simple question: How are you supposed to use the HMAC module in Ruby to create a HMAC with MD5 (that uses a secret)? The HMAC docs seem awfully thin. Thanks! ...

How to share code between model and controller in Rails?

Both my Rails model and controller code need to write files to the file system. I would like to consolidate the logic into one method. What's the best way to share this method across models and controllers? Thanks! ...

rails model :has_many with self arguments (NOT association)

Hello there, Well, I don't know if I'm completely wrong, but I really can't find a very practical and straight forward way to do something like this: class User < ActiveRecord::Base has_many :creations end but the thing is, I just want the user to have many creations if the user.developer == true where user.developer is just a boole...

Does ruby IO.read() lock?

I have a webservice method that reads a photo and returns its byte data. I'm currently doing the following: @photo_bytes = IO.read("/path/to/file") send_data(@photo_bytes, :filename => "filename", :type => "filetype", :disposition => "inline") I'm getting some strange behavior when calling this a lot... occasionally send_data is retur...

rails form_for styling

Is there a way to add styling to rails form_for and make it display inline? ...

Rails - CSV(export to CSV) loop

i want to do (export to CSV) in the form of fetching first 50 students and next 50 students and so on, in seperate files. i have tried with the below given code, and i dont know how to generate loop, please provide some code to do the process. @count =0 if @count == 0 students = Student.find(:all,:order => 'name', :limit => 50) @...

What kinds of concurrency/deadlock issues should one be aware of in Rails code?

I've just come to a realization about deadlocks - namely what they are - and I'm concerned about this issue affecting my Rails code. Are there any specific deadlock issues to watch out for while developing a Rails app? Have you ever encountered a deadlock in your Rails code - or is that even possible? (I'm not referring to database de...

Reading from TCPSocket is slow in Ruby / Rails

I have this simple piece of code that writes to a socket, then reads the response from the server. The server is very fast (responds within 5ms every time). However, while writing to the socket is quick -- reading the response from the socket is always MUCH slower. Any clues? module UriTester module UriInfo class << self ...

Rails: Scoped ID in addition to primary id

Say that I have many blogs, and each blog has_many posts. These are stored in 2 tables ("blogs" and "posts"). Is it possible to add an additional column (e.g. scoped_id) to the blog table which stores an ID, scoped by the blog. Example Blog: 1 - Posts - id: 1, scoped_id: 1 - id: 2, scoped_id: 2 - id: 3, scoped_id: 3 B...

Counting boolean values under rails

I have a standard master-detail relationship between two models in a RoR application. The detail records contain four boolean fields indicating presence / absence of something. When I display the detail records I want to add a summary indicating the number of records which have their boolean value set to True for each of the four boolea...