I would like to be able to automatically parse JSON objects into instance variables. For example, with this JSON.
require 'httparty'
json = HTTParty.get('http://api.dribbble.com/players/simplebits') #=> {"shots_count":150,"twitter_screen_name":"simplebits","avatar_url":"http://dribbble.com/system/users/1/avatars/thumb/dancederholm-peek...
I am trying to use the following code to convert a hash of options (e.g. { :opt1 => 'a', :opt2 => 'b' } ) into parameters to be appended to a URL (e.g. example.com/page?opt1=a&opt2=b):
ActionController::Routing::Route.new.build_query_string(options)
where options is the hash. I get the following error:
wrong number of arguments (0 fo...
Using MRI 1.9
When an exception is raised that causes a backtrace to be printed, it would often be immensely easier to debug if the backtrace showed the receiver and values of method parameters as well as the method name. Is there any way of doing this?
Think about situations such as passing a nil deep into library code that wasn't ex...
I want to add a has_many through association to a activerecord model class for each symbol in an array. for example
PeopleOrganisation::ROLES.each do |role|
has_many role.to_s.pluralize.to_sym, :through => :people_organisations, :source => :person,
:conditions => "people_organisations.role = '#{role.to_s}'" do
def << (ob...
I'm new to Ruby and need to take 10 character rfid token serial data (from arduino & parallax rfid reader) and convert it to a string. It doesn't look like anything is being added to string. I am getting the rfid token data in the terminal window when I scan the token if that helps.
require 'rubygems'
require 'serialport'
#params...
I'd like to extract out logic from the controllers to somewhere that it can be more DRY. What's the best way of handling something like the following in Rails?
For instance, as opposed to having the query in the controllers, I could place it in the model:
class SmoothieBlender < ActiveRecord::Base
belongs_to :user
def self.get_...
I get an error when i run:
vagrant@vagrantup:~$ sudo gem list
ERROR: Loading command: list (LoadError)
no such file to load -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::ListCommand
Even if I don't use sudo I get the same error message.
It's on Ubuntu 10.4 and I have installed zlib...
Hi,
I am currently developing a RubyGem that provides an executable.
The executable keeps track of the state of some log files using the FSSM gem.
This executable should get started, do something in background, and get stopped later on.
For example:
$ my_executable start
# do something different...
$ my_executable stop
I would firs...
I'm setting up a continuous integration server for an application that uses cucumber.
I'm trying to install cucumber gem on ubuntu linux 10.04 but it doesn't work on ruby 1.8.6. It works on ruby 1.8.7 but it doesn't solve my problem because cruisecontrolrb demands 1.8.6. I have found this link http://www.ruby-forum.com/topic/198581, and ...
For hi5 there is a way to validate email addresses by importing your contacts from a hotmail account. I want to try and automate this task but am running into trouble.
Steps to get to form page.
Create hotmail email account.
Using hotmail email, make a new hi5
account.
After creating an account do not add
photo, but navigate to home ...
Hey,
I have encountered a weird problem twice in the past 2 weeks and it's starting to piss me off.
I have this very simple code :
Rails.logger.debug "Is current_step frozen ? => #{@current_step.frozen?.inspect}"
@current_step += 1
Has you can (or not) imagine, this is what is displayed on my console :
Is current_step frozen ...
I just got finished watching a railscast episode #189 and the was using a bit_mask to store a value in the users table. I am trying to implement the same thing but when I test via irb I am getting errors. First can someone explain what this is actually going. I know what the first line is doing and part of the second line
ROLES = %w[adm...
Hi,
I have created a delegated Array class like this:
class LeadPartArray < DelegateClass(Array)
def <<(part, &block)
super(part) unless @arr.select{|p| p.text == part.text}.size > 0
end
def initialize(arr = [])
@arr = arr
super(@arr)
end
end
I am overriding the << method and I want to be able to pass a block ...
I am trying to verify if a text have been written to file (build.log) after executing a rake task which will throw an exception. Checkout both the code snippets below, the one with begin works whereas lambda throws a message saying it couldn't find the build.log file.
Using begin to test.(works)
begin
Rake::Task['git:checkout'...
Hi,
could you tell me plz - how to use in rails3 application external Active Record session store?
In rails2 its simply
ActiveRecord::SessionStore::Session.establish_connection("sessions_#{RAILS_ENV}")
but wat about rails3?
...
Perl allows you to use the '..' operator to return a slice from an array. So if I wanted cells 4 through 8 from an array, I could this:
sample_array[4..8]
And if I assigned that to a new array, it would only have those 5 cells. Is there an operator like this for Ruby?
Thanks.
...
I am trying to define a set of functions where I can pass in given params.
for example, how do i do the following?
>> get_1_type("xxx")
V4_RELATIONSHIP_TYPES=[1=>2,3=>4]
V4_RELATIONSHIP_TYPES.keys.each do |key|
self.class.send(:define_method, "get_#{key}_type".downcase) do
return GuidInfo.get_or_new(PARAMS, V4_RELATIONSHIP_TYPES[...
More of a syntax curiosity than a problem to solve...
I have two arrays of equal length, and want to iterate over them both at once - for example, to output both their values at a certain index.
@budget = [ 100, 150, 25, 105 ]
@actual = [ 120, 100, 50, 100 ]
I know that I can use each_index and index into the arrays like so:
@budget...
Hi,
I cant seem to figure out how to put text in between the generate textarea tags.
Is there a way to specify a value in the RoR textarea tag that will be placed between the generated textarea tags?
This is an example of the code I am using.
<% remote_form_for ... do |f| %>
<%= f.text_area :message, %>
<%= f.submit 'Upda...
Is there an equivalent for ruby's array[n..m] in Javascript ?
For example:
>> a = ['a','b','c','d','e','f','g']
>> a[0..2]
=> ['a','b','c']
Thanks
...