ruby

Rails: accessing field value from model method

Just started learning Rails (3). I am tearing my hair out trying to find how to do something presumably utterly trivial: access the value of a model instance's field, from inside a method on that model. In my case: def formal_name @title + " " + @forename + " " + @surname end All three @properties (which are all fields on the tabl...

Ruby gem installation problem on MAC which is behind firewall

Hi , Please provide me solution for the problem of, 1) How to install ruby gems on MAC PC(OSX 10.5.1) which is behind corporate firewall . Regards, Sun ...

Using authlogic_api for Rails REST API access

I am writing a Rails back-end API for a Steam game that is only accessed via REST calls, so no user-specific authentication is required. I am trying to implement the authlogic_api plug-in for the Authlogic gem, which uses an api_key/signature mechanism to restrict access. I have implemented the ApplicationSession and ApplicationAccount m...

How can I list files for an init.d script without ruby

I need to convert a init.d script that uses ruby to not use ruby. I can use perl or python or something else, but I can't use ruby. My main problem is figuring out how to dynamically get the list of *.jar files in a directory and separate them with ':'. The rest I could easily do with a bash script. Here is the Ruby code I'm working wit...

Using rails resources (REST), how can I use a form to filter results on GET requests (i.e. /products)

Hello, I'm new to rails and having trouble figuring out how to do this RESTfully. I have a route set as map.resources :products and what I want to do is have some way to filter the results returned from the index action. For example, you go to /products which calls the index action per the resources default, then on that page there is a...

Easier rubygems from command line?

Normally to use Ruby libraries from command line I can do something like: ruby -rfastercsv -e 'code' Unfortunately this doesn't work with rubygems, as they're not enabled by default, and whatever rubygems does to override require doesn't seem to work with -r switch, so I'm forced to do this instead: ruby -e 'require "rubygems"; requi...

Ruby Plugin Architecture

I'd like a very basic example of a tiny base program, that reads in two plugins and registers them. These two plugins hook into the base program in the same way in a unconflicting manner. I'm very new to metaprogramming in any programming language for that matter, I'm not sure where to start. ...

Complex hash editing with MVC/Padrino ruby 1.8.x

I'm new to MVC. I'm using Padrino with MongoMapper and Haml to try to create this application. I have a database of items, each of which has a hash associated with it called 'params'. This hash has some required keys, but mostly arbitrary/random keys. Some of the keys have a finite set of allowable values. For example: item.params["pa...

Rails 3 render :partials

Hi guys. I am migrating my 1.8.7 rails app to rails 3. But I have a problem with a partial: I have the following partial: in my cms controller : @clients = Client.all group = render_to_string :layout => 'layouts/window', :partial => 'clients/index' in my "clients/index" partial: <%= render :partial => 'clients/item', :collection ...

confusion about accepts_nested_attributes_for

Somehow, I was under impression that accepts_nested_attributes_for will let me populate child object through parent: person.update_attributes person_hash but in practice I ended up doing this: person.address.update_attributes person_hash[:address] person_hash.delete :address person.update_attributes person_hash Now, http://guid...

automatically including a plugin/gem's module in rails

I have a gem that I'm working on that contains a module that I'd like to be automatically included in my Rails app. For now, I've put the following: config.after_initialize do include MyModule end I'd like to not have to include this in the instructions for my app. It would be great if someone could install the gem/plugin and have t...

Error when using gchart (googlecharts) gem - NameError: uninitialized constant Gchart

http://googlecharts.rubyforge.org/ I installed it with: sudo gem install googlecharts It installed fine, but whenever I try to use it I get: NameError: uninitialized constant Gchart Here is the code I am running: $ irb >> require 'gchart' => true >> Gchart.line(:data => [0, 40, 10, 70, 20]) NameError: uninitialized constant Gchart ...

activerecord-sqlserver-adapter on Ubuntu

I followed the instructions found here to get my rails app to communicate with SQL Server on Ubuntu 10.04 http://wiki.github.com/rails-sqlserver/2000-2005-adapter/platform-installation-ubuntu-2 All the tests documented there have passes except the when I try script/sconsole I was able to make a db connection in irb In my app I have a ...

In Ruby, how do you refer to a function without invoking it, because foo is the same as foo() so it is already invoked

In Ruby, how do you refer to a function without invoking it, because foo is the same as foo() so it is already invoked. for example, puts.class is the same as puts().class ...

how is this table updated if there is no model file?

I'm trying to manually update a db in Spree, but it has no model file. I want to know how to CRUD into the option_values_variants table. The code uses James Golick's Resource Controller, but I want to do it without. models/option_value.rb class OptionValue < ActiveRecord::Base belongs_to :option_type acts_as_list :scope => :option...

MongoMapper newbie - Looks like I'm ending up with a relational database...

Hi there, I'm a mongo + mongomapper newbie, my question is, after following the examples in these slides: 1. http://www.slideshare.net/mongosf/ruby-development-and-mongomapper-john-nunemaker/39 2. Slide 40 3. Slide 41 I ended up with 2 collections joined on a foreign id... Is that right? I was expecting to see something similar to what...

git clone problem

i have create clone of project on local machine with git clone [email protected]:test/abc.git Now i want to deploy my project on my ubuntu server . so i have created a script which install git on my ubuntu server. And now i want to deploy my rails project on server. like git clone [email protected]:test/abc.git but i have not set ssh key ...

ruby on rails concatenating two active records objects

I have two complex rails (AR) queries coming from two different methods that I sometimes want to concatenate. The data structure returned in each object is the same I just want to append one onto another. Here's a simplified example (not my actual code): @peep1 = Person.find(1) @peep2 = Person.find(2) Thought something like this w...

How do I pipe my msbuild output to a log file from rake

I'm using the fabulous albacore gem with rake to build a new .NET project. My organization is still using NAnt, and there are lots of folks who expect to see a log file when the build script executes. How do I save the msbuild task output that gets dumped to STDOUT to a log file? ...

How can I access UrlWriter url/path generators from a model's class method?

I want to generate urls from a model's class method. I've done this before from an instance method by simply including ActionController::UrlWriter -- I tried including this in the instance definition scope and also the class definition scope, to no avail. class Foo < ActiveRecord::Base # only works for instance methods # include Act...