ruby

What does it mean for a programming language to be "on rails"?

I'm currently working with Groovy and Grails. While Groovy is pretty straight-forward since it's basically Java, I can't say I grok Grails. I read that Groovy is to Grails as Ruby is to Ruby on Rails, but what does that mean? ...

Error installing newgem on linux

I am trying to install newgem on my linux box (sudo gem install newgem) and i am getting the following error: Building native extensions. This could take a while... ERROR: Error installing newgem: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb install newgem extconf.rb:1:in `require': no such file to load --...

Ruby: How to post a file via HTTP as multipart/form-data?

I want to do an HTTP POST that looks like an HMTL form posted from a browser. Specifically, post some text fields and a file field. Posting text fields is straightforward, there's an example right there in the net/http rdocs, but I can't figure out how to post a file along with it. Net::HTTP doesn't look like the best idea. curb is loo...

Tax Service Recommendation for a Rails App?

I'm developing a cart that needs to calculate tax and am looking for a 3rd party tax service to handle the calculations. I've used Avalara in another app, but it's somewhat miserable since I have to use the Rjb gem with their java library. Does anyone have a recommendation for a tax service that works well with rails? ...

Has and belongs to many relationship with multiple databases

I have a situation where I have two models, companies and permissions, where companies is in a separate database from my permissions database. This is a has and belongs to many relationship because each company can have many permissions and each permission can belong to many companies. The reason the two databases are split is because ...

What is mattr_accessor in a Rails module?

I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is the Module corollary for 'attr_accessor' (getter & setter) in a normal Ruby class. Eg. in a class class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end end Eg. in a module module Authentica...

Ruby: define_method vs. def

As a programming exercise, I've written a Ruby snippet that creates a class, instantiates two objects from that class, monkeypatches one object, and relies on method_missing to monkeypatch the other one. Here's the deal. This works as intended: class Monkey def chatter puts "I am a chattering monkey!" end def met...

How do I change the title of a page in rails?

What is the best way to create a custom title for pages in a rails app with out using a plug-in? ...

RoR: What steps are you going through in the preparation phase of application development?

Let's say you already "know" what your client wants from you (i.e. you already did some analysis and have some clue about what are you supposed to deliver). What are the next steps you usually go through after this phase? In other words, what are the steps (in terms of preparation of the framework, plugins, repository, etc.) you do in th...

Why use Ruby instead of Smalltalk?

Ruby is becoming popular, largely from the influence Ruby on Rails, but it feels like it is currently struggling through its adolescence. There are a lot of similarities between Ruby and Smalltalk -- maglev is a testament to that. Despite having a more unusual syntax, Smalltalk has all (if not more) of the object-oriented beauty of Ruby....

How to query a model based off the controller name

I've been refactoring my models and controllers in an effort to remove code duplication, and so far it seems to be all peachy creamy. Currently I've got a bit of code that is common to two of my controllers, like so: def process_filters # Filter hash we're going to pass to the model filter_to_use = {} # To process filters, we firs...

Persisting an environment variable through ruby

I am trying to set my dos environment variable in ruby which persists after the script exits. For example if I want a ruby script set_abc_env.rb to set environment variable ABC to blah, I expect to have the following: C:> echo %ABC% C:> set_abc_env.rb C:> echo %ABC% blah How do I do this? ...

Ruby: builtin do ... while ?

Ruby has a wealth of conditional constructs, including if/unless, while/until etc. The while block from C while (condition) { ... } can be directly translated to Ruby: while condition ... end However, I can't seem to find a built-in equivalent in Ruby for a C-like do ... while block (in which the block contents are execu...

Deploying binary gems to a different platform

I have a Rails app that I need to deploy. Here are the facts: The app was developed on Windows and requires Windows binary gems The app is to be deployed onto an Open Solaris shared server (Joyent) I do not have permissions to install gems on the server For the non-binary gems, I can simply do a rake gems:unpack locally and then upload...

is_a? and dRuby objects

Hi, I'm working with dRuby and basicly I'm calling a remote method that returns me an object. In the clientside I have this code: handle_error(response) if response.is_a?(Error) where response is the DRbObject. (I've developed this code before using dRuby and I'm returning an Error object if something went wrong). The problem is tha...

setting ruby hash .default to a list

i thought i understood what the default method does to a hash... give a default value for a key if it doesn't exist irb(main):001:0> a = {} => {} irb(main):002:0> a.default = 4 => 4 irb(main):003:0> a[8] => 4 irb(main):004:0> a[9] += 1 => 5 irb(main):005:0> a => {9=>5} all good. but if i set the default to be a empty list, or empty...

Correct way to populate an Array with a Range in Ruby

I am working through a book which gives examples of Ranges being converted to equivalent arrays using their "to_a" methods When i run the code in irb I get the following warning warning: default `to_a' will be obsolete What is the the correct alternative to using to_a? are there alternate ways to populate an array with a Range? Ch...

Using a Windows Form with Ruby

Is it possible to create a form on Windows using Ruby? I have a Ruby script and I would like to have an input form to ask for a user's password, then use this in the rest of my script. update: I have successfully done this with wxRuby, although it looks ugly. Shoes looks promising, I might look into that if I need to do this again.. ...

Ruby Meta Programming Question

I was looking at the Ruby logging library Logging.logger method and have a question from the source at github relating to this piece of code: logger = ::Logging::Logger.new(name) logger.add_appenders appender logger.additive = false class << logger def close @appenders.each {|a| a.close} h = ::Logging::Repositor...

What is the best way to read the Rails session secret?

I would like to access the Rails session secret programmatically (I am using it to generate a sign-on token). Here's what I've come up with: ActionController::Base.session.first[:secret] This returns the session secret. However, every time you call ActionController::Base.session it adds another entry to an array so you end up with so...