ruby

How to run PHP code from inside a Ruby script?

I'm trying to come up with a solution to this problem. I have a Ruby script that needs to run some PHP code, but I am new to Ruby, so I don't know how to go about doing this. def run_my_code #execute some PHP code here # $person = new Person(); # $person->doSomething(); end How can I achieve this? ...

Can i pass method name as argument with super ?

I have created a common controller for my application. class CommonController < ApplicationController def index # My stuff end end And in my other controller i am using super to call my index method like this. class Other1Controller < CommonController def index super end end class Other2Controller < CommonController ...

what is ||= in ruby?

Possible Duplicate: What does ||= mean in Ruby? what is ||= in ruby? ...

Asynchronously iterating over the response of a request using Thin and Sinatra

If your response in Sinatra returns an 'eachable' object, Sinatra's event loop will 'each' your result and yield the results in a streaming fashion as the HTTP response. However, if there are concurrent requests to Sinatra, it will iterate through all the elements of one response before handling another request. If we have a cursor to ...

Why does a local variable lose its value when defining a method with define_method?

Trying to follow along with a metaprogramming screencast from pragpub and ran into some problems because of changes in Ruby since the release of screencast. Hard to explain the problem w/o the code, so here's that: class Discounter def discount(*skus) expensive_discount_calculation(*skus) end private def expensive_discou...

Watir: Can I open the file explorer from file_fields?

So I know I can add a filepath to a file element type using Watir, but is it possible to open up the file explorer to select a file to upload? Or is the only way to just enter the path using .file_fields? ...

Accessing a RoR ActiveRecord's attributes from within the ActiveRecord instance

Hi, I am confused about how to access the attributes of an ActiveRecord instance from a method within the ActiveRecord instance. For example I have a Lead class that inherits from ActiveRecord: class Lead < ActiveRecord::Base end I have the following scaled down migration file that shows the columns of an ActiveRecord table: class ...

mapping to value in deep hash

Hi all, I'm doing an application using mongodb and mongoid and I'm facing a problem where I need to map something in one document to something in another document. My plan is to store something in a document that I can then use to figure out what value for it to fetch from a different collection. But, this is more generally a ruby quest...

How do I implement an atomic stack with mongoDB and Ruby

I want to push and pull things off of a stack in an atomic way using ruby and mongoDB. The push I can do atomically via the following code example: collection.update({"_id" => document["_id"]}, {"$push" => {field_name => value}}) Example code for pop: value = collection.update({"_id" => document["_id"]}, {"$pop" => {field_name => -1...

how does ruby handle array range accessing?

ruby-1.8.7-p174 > [0,1][2..3] => [] ruby-1.8.7-p174 > [0,1][3..4] => nil In a 0-index setting where index 2, 3, and 4 are all in fact out of bounds of the 2-item array, why would these return different values? ...

Rails Users has_one :profile vs. show page

Hello, I have a best practice/efficiency/performance issue. If I want to have a profile page for each user in my system and i already have a user model. Is it better to have all the users information in the user model and pull it on the show page of users so users/show will access the user model and grab all the relevant data like a...

How do i skip activation in rails?

I am using the restful authentication plugin in rails and i need to skip the authorization and log the user in immediately...How can this be done Any ideas would be highly appreciated ...

gem installed but 'rails' commands don't work

when I run any rails command like rails s I get the following error: Could not find diff-lcs-1.1.2 in any of the sources Try running bundle install. However, I already installed diff-lcs. bundle show diff-lcs /opt/local/lib/ruby1.9/gems/1.9.1/gems/diff-lcs-1.1.2 I also see diff-lcs when I do a gem list command My GEM_HOME is /...

rails, preview button in form question

Hi, I am trying to set up a preview button in an edit form based on the railscast by Ryan Bates. There are two buttons [edit] and [update]. When the user clicks the preview button, the "update" function in the controller is called. If I simply set the @article variable based on a find of the article table (as per below controller) th...

rails nested form, create and then update new associated models without page reload

Relevant info I have a User model with plenties of attributes and several has_many associations. I have a BIG form to edite existing user info, including nested fields. I have divided the form into several forms in different divs and show only one form at a time. (i.e. tabs in UI) User can save info by clicking Save button, which subm...

Rake 0.8.7 and ActiveSupport 3.0.1

Hello guys, I am running Ruby 1.9.2. I have rake 0.8.7 installed. However running rake inside a Rails application gives me the following: (in /usr/home/users/dimitar/Rails/spek) Could not find activesupport-3.0.1 in any of the sources Try running `bundle install`. So I go ahead and run bundle install again and everything looks good: ...

How can GNOME keyrings be accessed from Ruby?

I need to access GNOME keyrings from the Ruby programming language. However, I can't find any ruby libraries of gems. Specifically, I'm trying to get the Oauth keys for desktopcouch. How can this be acheived? ...

html table to array ruby

i am screenscraping using watir and i download a xls file. when i open this file in notepad, i find that its just a bunch of html tables. is there a any function or gem that will convert this page into a bunch of arrays. any ideas is appreciated. ...

Why is the route not finding the the decimal

Ok so i have an application that i use this jquery $("#band_events").load("/load_events/"+ escape($('#request_artist').val()), successCallback ); It works great but if #request_artist is R.E.M. or somehthing with decimals or something weird rails has problems like ActionController::RoutingError (No route matches "/load_events/R.E.M....

Rails find or create based on two fields

I have a venue model and i want to do this Venue.find_or_create_by_ but i only want a new venue to be created if one with the same name and date do not already exist For example => Venue(id: integer, location: string, showdate: datetime, created_at: datetime, updated_at: datetime) A venue is unique and needs to be created if the l...