Displaying 20 results from an estimated 110000 matches similar to: "ruby issue : mixing Hash and Array"
2006 Aug 11
2
Array#chunk method, maybe someone will find this useful
class Array
# break an array up into <size> chunks
def chunk(size=1)
return self if self.empty?
raise ArgumentError if !size.kind_of? Integer
y = self.length.divmod(size)
rows = (y[1] > 0) ? y[0] + 1 : y[0]
arr = Array.new(rows)
(0...rows).each do |i|
arr[i] = self.slice(size*i, size)
end
(arr.last.length...size).each { |i| arr.last[i] = nil }
2009 May 27
12
query on Ruby array
Looking for suggestions on following two queries.
Query 1
------------------------------
Are the two following lines of code different in Ruby / Rails ( in a
*.html.erb) file.
<% if @forms.count != 0 %> <!-- first code -->
Vs.
<% if @forms.count %> <!--second code -->
@forms is an array of objects. Coming from "C" language development
background, i thought
2007 Jul 29
1
Curious why this doesn't work. (has_many, belongs_to)
Two Models.
class Gm < ActiveRecord::Base
belongs_to :pool
# mode code here.
end
class Pool < ActiveRecord::Base
has_many :gms
# mode code here.
end
Testing code through the console.
>> gm_list.each{ | gm | puts " GM name: #{ gm.user_name } belongs to Pool: #{ gm.pool.pool_name } " }; nil
GM name: John belongs to Pool: RHP 07-08 Season - Career League
GM name:
2006 May 09
2
newbie: OSX Ruby/MySQL issue?
I''m three pages into the OnLamp RoR Tutorial [1] and am wrestling
with what appears to be a MySQL connection problem.
I''ve created a simple controller called "recipe" with a corresponding
"recipes" mysql table. The recipe controller is just a simple scaffold.
When I browse to "recipe/new", though, I get these errors:
==
NoMethodError in
2013 Feb 11
5
split dates array with take_while does not work ?
I wonder why ruby core method ''take_while'' does not work as expected in the
below Rails console example:
irb(main):003:0> arr = []
=> []
irb(main):004:0> arr << Date.today - 15.days
=> [Sun, 27 Jan 2013]
irb(main):005:0> arr << Date.today - 25.days
=> [Sun, 27 Jan 2013, Thu, 17 Jan 2013]
irb(main):006:0> arr << Date.today
=> [Sun, 27
2008 Jul 16
3
constructor in model
Hi all,
I have an activation model that when constructed should set the key
(column in the activations table) to test.
class Activation < ActiveRecord::Base
belongs_to :user
def initialize
this.key = "test"
end
end
When i do ac = Activation.new I gget
NoMethodError: You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
2009 Jan 21
3
Nested serialization with to_json and to_xml with array and hash element
Title: Nested serialization with to_json and to_xml with array and
hash element
class Person < ActiveRecord::Base
has_one :address
has_one :job
def office()
return "Executive_Suite"
end
end
class Address < ActiveRecord::Base
belongs_to :person
end
class Job < ActiveRecord::Base
belongs_to :person
has_one :paygrade
def Title
return "Engineer"
end
end
2006 Mar 28
5
Anyone use .uniq! ???
could anyone by chance give me a working example of the .uniq! method?
i''ve been trying all day. any help would be much appreciated!
jon
--
Posted via http://www.ruby-forum.com/.
2008 Mar 05
7
mocking successive return values
I''m having a problems mocking successive return values. I don''t know
if I''m doing something wrong or if this is a limitation of rspec
mocks. Any ideas of what I may be doing wrong?
I''m trying to test the generate_quote_number method. It generates a
quote number, looks to see if it is in the db already. If it is, it
calls itself to try again. I want
2006 Aug 16
7
ActionWebService: XMLRPC Server Multicall possible?
Hi all,
I have a question concerning ActionWebService XMLRPC servers: Is it
possible to send multicall requests to the Web service? I tried to
use multicall and get the error message:
no such method ''system.multicall'' on API [MyAPI]
In Changeset 2021 there is the following commit message:
add ''system.multicall'' support to XML-RPC. boxcarred methods must
2006 Jun 15
6
Newbie''s problem with a nil object he didn''t expect!
Dear Rubyists/Rails gurus,
Though I''ve successfully completed the various Rails tutorials online
and the Depot application from the Agile Web Development with Rails
book, I''m still pretty much a Ruby/Rails newbie. I''m trying to learn by
writing my own simple blogging application, but I''ve run into a problem
that has had me scratching my head for a few days now.
2012 Jun 30
5
Problems with associations
Hello guys, I have two tables, tasks and projects, and each model I put:
Task.rb
class Task < ActiveRecord::Base
attr_accessible :user_id, :project_id, :name
belongs_to :project
end
Project.rb
class Project < ActiveRecord::Base
attr_accessible :name, :description
has_many :tasks
end
But when I go to my prompt and I make a SELECT with task, none project
is returned.
2008 Jan 30
2
(no subject)
Message-ID:<ef1d468f0801291747q3f605e6cjb73028a888a441ee at mail.gmail.com>
On: Tue, 29 Jan 2008 20:47:41 -0500, "Andrew WC Brown" <omen.king at gmail.com>
wrote:
> I''ve seen lambda before but not sure what it does.
A lambda is a fancy name for an anonymous or unbound function. Its
significance comes from the fact that it is completely stateless, producing no
2008 May 09
2
attr_accessor_with_default funny
I created some virtual attributes in a model in order to store
intermediate calculated values. I wanted to use
attr_accessor_with_default so that I could give the calculated values
an initial value to allow me to use += to easily accumulate values.
When I did so I came across some slightly perplexing behaviour which I
was wondering if anybody could explain to me.
When I tried to create a method
2006 Apr 15
6
view code regular expression
I''m lost on regular expressions to begin with...
I''m trying to fix a value to one of 4 radio buttons as there will be
value of either 1,2,3 or 4 in @roles_users...
<TD><input type="radio" id="roles"
name="case_managers[case_manager_name]"
value="Case Manager Admin"
<% if =~ @roles_users /1/ checked =
2006 Mar 24
8
[OT] Does Net::HTTP support secure connections ?
Hi !
I''m trying to connect to an https URL, but it seems it doesn''t work.
Has anyone successfully connected from Ruby to an HTTPS server ?
Thanks !
--
Fran?ois Beausoleil
http://blog.teksol.info/
2006 Jul 19
5
weird result for a custom attr reader!
Hi all,
I am having a weird problem reading a value from my model. basicaly, I
have these two models:
class Category < ActiveRecord::Base
acts_as_tree :order => "name"
belongs_to :item_type
has_many :specific_category_names
end
and
class SpecificCategoryName < ActiveRecord::Base
set_table_name "Specific_category_names"
has_many :products
belongs_to
2006 Apr 23
37
Newbie .. nil object and missing something obvious
Trying to do first project in Ruby on Rails, and I''m getting the dreaded
nil object exception. I''ve reduced the code to what I think is the
minimal case, and it''s still not working. Code presented below..
----------------------------------------------------------------------
in "app/controllers/dashboard_controller.rb"
class DashboardController <
2006 Mar 18
4
Mongrel Console 0.1 -- script/console meets mongrel
This is a super quick announcement for a new Mongrel plugin called
mongrel_console. It was inspired by a request from Tobias L?tke who wanted
to tail out logs while Mongrel was running.
What mongrel_console does is combine the Rails script/console with Mongrel
so that you can control a mongrel server while using script/console. Sounds
weird but it''s quite awesome for development
2007 Nov 01
3
autotest debugger?
Hi,
I keep facing problems with autotest, and I don''t know what''s happening
in the background, is there anyway to know what''s happening while
testing?
Example:
@user = User.new
@user.email = "testcom"
@user.errors.on(:email).should_not be_empty
...throws error failure
- You have a nil object when you didn''t expect it!
- You might have expected an