On 4 February 2016 at 15:54, nanaya wrote:
>
>
> On Fri, Feb 5, 2016, at 00:50, Colin Law wrote:
>> You don't need the first two lines, you just need something like
>> Initiative.all.map {|initiative| [initiative.name,
>> initiative.trainings.count] }
Who cares? Always initially write the simple
On Fri, Feb 5, 2016, at 00:50, Colin Law wrote:
> You don't need the first two lines, you just need something like
> Initiative.all.map {|initiative| [initiative.name,
> initiative.trainings.count] }
>
That'll be slow. The alternative is to include `:trainings` but then
it'll transfer a bunch o
On 4 February 2016 at 15:30, John Sanderbeck wrote:
> I am new to Rails and Ruby and am having a difficult time building the
> data needed for a Highchart. I am struggling with the syntax to map a
> pair of hashes to an array. Let me try and explain:
>
> I have a table of "initiatives" which conta
Hi,
On Fri, Feb 5, 2016, at 00:30, John Sanderbeck wrote:
> I am new to Rails and Ruby and am having a difficult time building the
> data needed for a Highchart. I am struggling with the syntax to map a
> pair of hashes to an array. Let me try and explain:
>
> I have a table of "initiatives" whic
I am new to Rails and Ruby and am having a difficult time building the
data needed for a Highchart. I am struggling with the syntax to map a
pair of hashes to an array. Let me try and explain:
I have a table of "initiatives" which contains basically an ID and a
Name.
Then I have a table "training
> On 2015-Dec-16, at 17:24 , Scott Eisenberg wrote:
>
> Looks to me like you will have an Array of hashes.
>
> The ruby way something like a single line array select
>
> t.select{|tt| a.between?(tt[:min], tt[:max]) && b.between?(tt[:b_min],
> tt[:b_max])}
>
> create the array initially with
Looks to me like you will have an Array of hashes.
The ruby way something like a single line array select
t.select{|tt| a.between?(tt[:min], tt[:max]) && b.between?(tt[:b_min],
tt[:b_max])}
create the array initially with something like
t = Array.new
t << {a_min: 1, a_max:10, b_min: 100, b_ma
Hi all,
I am a newbie in Ruby, and I am having a small question with the hash
table. If anyone could give me some suggestions that would be great!
Considering creating a hash table like this:
a_Min a_Max b_Min b_Max p1 p2 p3p4
p5 p6
On 26 April 2015 at 17:57, Gaohong Wei wrote:
> I have defined an instance variable as Hash in controller. When the instance
> variable is retrieved in View, its type is String, and the value is string
> too.
> Something wrong?
Yes, something is wrong, obviously. Unfortunately it is not possible
On Sun, Apr 26, 2015 at 11:57 AM, Gaohong Wei wrote:
> I have defined an instance variable as Hash in controller. When
> the instance variable is retrieved in View, its type is String, and the
> value is string too.
> Something wrong?
>
Can't tell without seeing code.
--
You received this mess
I have defined an instance variable as Hash in controller. When
the instance variable is retrieved in View, its type is String, and the
value is string too.
Something wrong?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe
Hey guys,
I had recently a very weird experience. I have a Loader class that run's a
lot of different things on Active Record objects. One thing this loader
does, is to preload data based on each classes settings. so basically:
scope.preload(preloads)
scope has a collection of Active Record ob
So I have been struggling with an issue for a while now and seem to be
getting nowhere...
The problem exists while I am looping through a hash, around the 3rd level
deep.
So my code looks a little like:
request[:items][:location_item].each do |locaton_item|
pp location_item[:name]
location
Apparently ruby 1.9 allows a shortcut hash creation/assignment syntax
h = {foo: "bar"}
=> {:foo=>"bar"}
I ran across this today after converting an application to rails 3.1
over the last few month with release candidates and trying test
deploying it. The application was developed using ruby 1.9.
On 30 June 2011 13:27, Sebastian wrote:
> I have a hash that has a :status key. The value could be 'new' or
> 'old'.
>
> Now I want to get only the entries where status is 'new'. I know how
> to do this with an if-clause, but there has to be a better way.
Do you mean you have an array of hashes?
Hi,
this is actually a Ruby question, but I hope I get an answer anyway.
I am looking for a "hash.each.where" function, but I can't find
anything.
I have a hash that has a :status key. The value could be 'new' or
'old'.
Now I want to get only the entries where status is 'new'. I know how
to do
> Hey all,
>
> Hash vs methods may seem like a silly question, but in certain
> situations I don't understand why you would use a method over a hash.
> For example, take a look at this method:
>
> #this is defined in a class called core.rb
> def assign_attributes(attributes)
> attributes.each_pa
Hey all,
Hash vs methods may seem like a silly question, but in certain
situations I don't understand why you would use a method over a hash.
For example, take a look at this method:
#this is defined in a class called core.rb
def assign_attributes(attributes)
attributes.each_pair { |k,v| send("
On 25 February 2011 11:26, Vijay Ra wrote:
> Hello I m newbie in rails
> i create simple application which take data from user search in DB and
> show output but it not show properly it's show what i want plus it show
> whole hash elements which is i don't want. i am attaching output screen
> shot
Hello I m newbie in rails
i create simple application which take data from user search in DB and
show output but it not show properly it's show what i want plus it show
whole hash elements which is i don't want. i am attaching output screen
shot here
Here r my app files
==
ooops. sorry. should be
@myhash.collect {|k,v| "#{k} is #{v}"}.join
On Wed, Feb 16, 2011 at 8:19 AM, Jim Ruther Nill wrote:
> can't you use collect? and then join the result?
>
> @myhash.each {|k,v| "#{k} is #{v}"}.join
>
>
> On Wed, Feb 16, 2011 at 12:46 AM, Paul Bergstrom wrote:
>
>> Why does
can't you use collect? and then join the result?
@myhash.each {|k,v| "#{k} is #{v}"}.join
On Wed, Feb 16, 2011 at 12:46 AM, Paul Bergstrom wrote:
> Why does this output the same hash again (like hash.inspect) and not
> each key as I want?
>
> @myhash.each { |k,v| "" + k + "" }
>
> --
> Posted vi
Or since only keys are needed, use each_key iterator.
Also, I think ri should say that the "method" each "returns" the same Hash
on which you called the method.
-Kedar
On Tue, Feb 15, 2011 at 8:57 AM, Colin Law wrote:
> On 15 February 2011 16:46, Paul Bergstrom wrote:
> > Why does this output
On 15 February 2011 16:46, Paul Bergstrom wrote:
> Why does this output the same hash again (like hash.inspect) and not
> each key as I want?
>
> @myhash.each { |k,v| "" + k + "" }
Because it is showing the return value of the method each, not what
you are doing in the block. You need to build u
Why does this output the same hash again (like hash.inspect) and not
each key as I want?
@myhash.each { |k,v| "" + k + "" }
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group
In Rails, we can see the following for example (They are separate here):
:x=>"new_x"
:y=>{:x=>X.new}
>From Ruby, I know that a hash has to be between { }, and the key is on
the left of => and the value to the right.
But, in the above examples we are seeing => everywhere! What is => ? Is
it like
On Apr 5, 2010, at 7:36 PM, Me wrote:
I found a method to convert the keys that are string to symbols. I
included the file in the lib directory but when I call it it says it
does not recognize the method. Ideas?
class Hash
# Recursively replace key names that should be symbols with symbols.
I found a method to convert the keys that are string to symbols. I
included the file in the lib directory but when I call it it says it
does not recognize the method. Ideas?
class Hash
# Recursively replace key names that should be symbols with symbols.
def key_strings_to_symbols!
r = Ha
On 18 March 2010 13:43, ES wrote:
> I'm trying to create a data entry form but getting an error when it
> sumbmits. I am using an hash to get the names of the fields definied
> in the controller's "new" function:
>
> def new
> �...@thing = thing.new
> �...@columns = Hash.new
>
> �...@colum
On 18 March 2010 13:43, ES wrote:
> the first time I load the page, the correct form displays but then
> when I click submit, I get this error :
>
> You have a nil object when you didn't expect it!
> You might have expected an instance of ActiveRecord::Base.
> The error occurred while evaluating n
I'm trying to create a data entry form but getting an error when it
sumbmits. I am using an hash to get the names of the fields definied
in the controller's "new" function:
def new
@thing = thing.new
@columns = Hash.new
@columns['thing_general'] = [
["title","name"],
I have the following hash myhash
{ "inter" => "team", "shirt" => "stripe" }
desired output
inter=team&shirt=stripe
I tried url_for myhash but got undefined method `url_for' for
thanks
--
Posted via http://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You re
Hi Guyz,
Problem with me is that whenever i am storing values in my hash.. it
stores perfectly ..
But when i am trying to print it .. i mean try to view its contents ..
then contents coming in wrong order .. which i dont want ..
Can sum one help me bit about it .. ?
--
Posted via http://www.ru
Hi all!
I have a Place model with a description attribute and a Service model
with an itinerary attribute. An itinerary is simply a string with
dash-seprated place descriptions. In my services_controller.rb#create i
have the following code:
itinerary = params[:places].merge(params[:places]){|id,
Heya,
I think I have thinking barrier. I just want a simple hash out of an
ActiveRecord.
@attributes = Attribute.find_all_by_character_id(@character).hash {
|u| [u.name, u.value] }
and I would like to access it like
@attributes[:health]
but it doesn't work. Anyone can help me out with that?
-
Hello all
I have problem regarding hash and array
I am retriving records using find method and then doing some operations
on it
and finally i got results like following
[{"1"=>"75225", "2"=>"Sat"},{"1"=>"75225", "2"=>"Sat"}]
which contains array of hashes
when we write simple find method of a
Hello all
any one has idea how to add new column to existing hash array ?
I have one hash instance like
@restaurant
using each with index i m looping it and want to add new key and value
to each row
how can i do that ?
please help me
thanks
--
Posted via http://www.ruby-forum.com/.
--~--~-
Hi all,
I've got a simple problem and I am wondering if it can be solved.
In my code I use Hash params name including white spaces (coming from
legacy database). They works well in my View, but I am not able to
properly use them later in my controller.
For instance, in my view I have:
It works
Hi,
My hash contain key as a combination of album date created_at and
album_id and values are some photo object.and i need to sort this hash
based on key; but i need to sort it also considering date created_at.
but if i consider a key as combination of both (date creataed and
album_id) then it i
39 matches
Mail list logo