ruby

Ruby Rails :has_many, autosetting a column

Given the following Ruby-on-Rails code (1.8.6, 2.3.5): class MyClass < ActiveRecord::Base has_many :modifiers, :conditions => ["affects_class = ?", self.name], :foreign_key => :affects_id end What I'm trying to do is to automatically set the affects_class column to 'MyClass'. In other words: myInstance = MyClass.find(:firs...

ActiveScaffold: How do I set the default value for a drop down list?

So I have this create form to create schedules where there is a bunch of fields and one of them is seasons. And seasons table has a field called 'is_current' which if set to 1 tells us that it is the current season. When the create form is display , I want the current season to be selected by default in the seasons drop down. Any help wi...

calling ruby with ajax

Hello all, I'm wanting to check a ruby session variable via ajax. I'm familiar with ajax calling php, is calling a ruby file similar? I'm talking about a 'session[:var_name]' type variable in a Rails environment using JQuery. Something like: $.ajax({ url: path to ruby file, type: "GET", dataType: "html", success: function(html){ .....

Importing existing git repo into assembla

Hi, Currently I have an website on a .zip file containing also the .git directory and all the history. I want it to be imported into an Assembla git repository preserving the history of all previous changes. Is there an easy way of doing it? ...

Why is this Ruby 1.9 code resulting in an empty hash?

I'm trying to zip 3 arrays into a hash. The hash is coming up empty, though. Here's sample code to reproduce using Ruby 1.9: >> foo0 = ["a","b"] => ["a", "b"] >> foo1 = ["c","d"] => ["c", "d"] >> foo2 = ["e", "f"] => ["e", "f"] >> h = Hash[foo0.zip(foo1, foo2)] => {} I'd like to zip these and then do something like: h.each_pair do |l...

What command line options are available for test/unit in ruby 1.9.1?

What command line options are available if you're using the Test::Unit compatibility layer in ruby 1.9.1? Background: ruby test/test_all.rb --help provides information on what command line options are available in ruby 1.8.7, but not in ruby 1.9.1 without the test-unit gem. Looking under Test and Test::Unit for ruby 1.9.1 rdoc doesn'...

Ruby 1.9: turn these 4 arrays into hash of key/value pairs

I have four arrays that are coming in from the client. Let's say that there is an array of names, birth dates, favorite color and location. The idea is I want a hash later where each name will have a hash with respective attributes: Example date coming from the client: [name0, name1, name2, name3] [loc0, loc1] [favcololor0, favcolor1] ...

How to write to file in Ruby?

I need to read the data out of database and then save it in a text file, how can I do that in Ruby? Is there any file management system in Ruby? Thanks ...

Ruby on Rails 2.3.5: Populating my prod and devel database with data (migration or fixture?)

I need to populate my production database app with data in particular tables. This is before anyone ever even touches the application. This data would also be required in development mode as it's required for testing against. Fixtures are normally the way to go for testing data, but what's the "best practice" for Ruby on Rails to ship th...

rails convert string to number

hi guys, i am wondering is there a convenient function in rails to convert string with negative signs into a number. e.g. -1005.32 when i use to_f method, the number will simply become 1005 with the negative sign and decimal part being ignored. thanks in advance! ...

Multiple instance_of?

How would I make Object#instance_of? accept multiple arguments so that something like the below example would work? class Foo; end class Bar; end class Baz; end my_foo = Foo.new my_bar = Bar.new my_baz = Baz.new my_foo.instance_of?(Foo, Bar) # => true my_bar.instance_of?(Foo, Bar) # => true my_baz.instance_of?(Foo, Bar) # => false ...

Multidimensional each

How would I do something like below? [ 'foo' ['bar', 'baz'], [ 'one', ['two', 'three'] ] ].each { |word| puts word } # I want this to return: foo bar baz one two three ...

How do I use has_many :through and in_place_edit?

I have two Models: Campaign and Contact. A Campaign has_many Contacts. A Contact has_many Campaigns. Currently, each Contact has a contact.date_entered attribute. A Campaign uses that date as the ate to count down to the different Events that belong_to the Campaign. However, there are situations where a Campaign for a specific Conta...

Is it possible to use partials with the layout option inside of a controller?

When try I following code in a controller, the view renders without using the layout def xyz render :partial => 'platinum_home', :layout => 'platinum_layout' end But If I do the following inside the partial <% render(:layout => "platinum_layout") do %> blah blah blah <% end %> It works just fine, is the first example not ...

Date Select in Rails

Hello, I want to use an input field and beside the input field should be displayed an date select field in which the user can choose the date and this date will then be filled in the input field. Do you know an easy solution without using prototype? Thanks for your help, Matthias ...

locale based sorting function in ruby

For my application(Ruby on Rails) i have country select box for the signup page. These countries are localized into different language. But i couldnt find a way to sort them, based on the language in which its localized. At present i have sorted it out based on english only. Is there a way to sort the country names based on the locale? i...

CSRF protection and cross site form access

Hi. I aw working on cross site authentication (some domains have got common authentication). So I want to send authentication data (login, password) to main domain from others. How should I use protect_from_forgery and how can I check if data received from valid domain? What I am thinking now is to turn off protect_from_forgery for se...

globalize2 - create_translation_table! and options for columns

Hi, could you tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null => false, :default => "abc" ??? ...

How would I go about letting a user add and associate a comma separated list of categories while adding an entry?

I've been struggling for quite a while to get this feature working: I want my user to be able to select categories when uploading a photograph, but additionally be able to specify a comma-separated list of categories to create/find and associate with the photograph. I've had this working by using an attr_accessor :new_categories on the ...

Howto - Running Redmine on mongrel as a service on windows

I use Redmine on Mongrel as a project manager and I use a batch file (start-redmine.bat) to start the redmine in mongrel. There are 2 issues with my setup: 1. I have a running IIS on the server that occupies the HTTP port (80) 2. The start-redmine.bat must be periodically checked to see if it's stopped after a restart that is caused by w...