Best way to write this calculation in ruby.
amt = self.alt_inv - (self.alt_tax ? self.alt_tax : 0) - (self.alt_freight ? self.alt_freight : 0) - (self.misc1_amt ? self.misc1_amt : 0) - (self.misc2_amt ? self.misc2_amt : 0) ...
amt = self.alt_inv - (self.alt_tax ? self.alt_tax : 0) - (self.alt_freight ? self.alt_freight : 0) - (self.misc1_amt ? self.misc1_amt : 0) - (self.misc2_amt ? self.misc2_amt : 0) ...
Hi, I have written a method in Ruby to find all the circular combination of a text x = "ABCDE" (x.length).times do puts x x = x[1..x.length] + x[0].chr end Is there a better way to implement this ? ...
Is there any Hijri Date library in Ruby? ...
I am parsing an XML doc that looks something like this: <MyBook> <title>Favorite Poems</title> <issn>123-456</issn> <pages>45</pages> </MyBook> <MyBook> <title>Chocolate Desserts</title> <issn>654-098</issn> <pages>100</pages> </MyBook> <MyBook> <title>Jabberwocky</title> <issn>454-545</issn> <pages>19</pages>...
I'm returning to RoR after not using it for a few years and I'm trying to use ActiveModel to serialise a plain object to XML. I'm doing the following, as per the comments in activemodel/lib/activemodel/serialization.rb: class XmlError include ActiveModel::Serializers::Xml attr_accessor :code attr_accessor :description def at...
Hi, I have a String and I want to get another string out of it which has only characters at odd occuring positions. For example if i have a string called ABCDEFGH, the output I expect is ACEG since the character indexes are at 0,2,4,6 respectively. I did it using a loop, but there should be one line implementation in Ruby (perhaps usin...
I'm not sure if this can even be achieved, but here goes... :) Lets assume two models, a Page model and a Field model. A Page has_many :fields and the Field model has two attributes: :name, :value What I want to achieve is in the Page model to dynamically define instance methods for each Field#name returning the Field#value. So if my ...
In Ruby def my_func(foo,bar,*zim) [foo, bar, zim].collect(&:inspect) end puts my_func(1,2,3,4,5) # 1 # 2 # [3, 4, 5] In PHP (5.3) function my_func($foo, $bar, ... ){ #... } What's the best way to to do this in PHP? ...
I wonder if there are cheat cheets for all design patterns implemented in Ruby so that you don't have to reinvent the wheel. ...
I cannot get this crazy dependency to work and please don't tell me to go to Snow Leopard because I have a PPC. I have oniguruma, textpow, ultraviolet all installed. I'm using rvm which is probably the problem. Not that rvm is bad it's just that I don't know how to get the paths correct. When I startup a rails app the error I'm getting...
I'm really used to auto-completion coming from Netbeans. In Netbeans, when I type a 'string' and then hit a 'dot' it will print out a list of methods for the String class. TextMate doesn't seem to have that function. Is it something you could add? Would save A LOT of time instead of using the ri/irb/online doc all the time. ...
Hi I am having a problem with the form_for method in Rails. It is behaving strangely. I have a route with a path prefix, something like: map.resources :beers, :path_prefix => '/:brewery' And I have a form like this (@beer.brewery is a string, just the name of the brewery): <% form_for @beer, :url => { :brewery => @beer.brewery } d...
Hi , I need to generate a list of receipts in rails which need to be ordered by item's order relationship field (payment_method_meta_type.name). Models : Receipt Deposit PaymentMethodMetaType In Deposit Model: class Deposit < ActiveRecord::Base belongs_to :payment_method_meta_type has_many :receipts, :class_name=>"Receipt", ...
following a RoR security tutorial (here), i wrote something along the lines of @@private_re = // def secure? action_name =~ @@private_re end the idea is that in the base case, this shouldn't match anything, and return nil. problem is that it doesn't. i've worked around for the time being by using a nonsensical string, but i'd like t...
I've read this SO question on how to rotate a two-dimensional array many times, and I was curious as to how you could expand this situation to work with a section of a two-dimensional array. I've thought about it for a while, and I can't seem to come up with a good equation. Essentially what I'm wanting to do is something like this: ...
Ps: I don't want to use tk ...
I'm a big Haml/Sass fan. Right now I work with a designer who prefers Erb and doesn't speak Haml. I find that working with Erb is slowing me down considerably, and it doesn't seem fair that he should have to pay for that time (he's the client & I'm paid hourly). The erb->haml converter works quite well these days, but I don't know if t...
I run a Windows XP machine, and use Cygwin to run my ruby environment. I usually connect to a MySQL database, but for purposes of testing the application when using a SQL Server database I need to setup a connection to my SQL Server database. Does anyone know how to setup my environment to connect to SQL Server? ...
I need to access xml that is located in another web server. Does rails/ruby have a function that allows me to access this xml and then may be store it in a variable so that i can process it with libxml-ruby? ...
I've got a file named Vagrantfile and it's a ruby file but it cannot have the .rb at the end of the filename. Is there a way to tell Netbeans that it's Ruby file? ...