Re: [Rails] Hash mapping

2016-02-04 Thread Colin Law
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

Re: [Rails] Hash mapping

2016-02-04 Thread nanaya
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

Re: [Rails] Hash mapping

2016-02-04 Thread Colin Law
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

Re: [Rails] Hash mapping

2016-02-04 Thread nanaya
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

[Rails] Hash mapping

2016-02-04 Thread John Sanderbeck
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

Re: [Rails] Hash table

2015-12-16 Thread Rob Biedenharn
> 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

Re: [Rails] Hash table

2015-12-16 Thread Scott Eisenberg
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

[Rails] Hash table

2015-12-16 Thread Suo Huang
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

Re: [Rails] Hash is treated as string in Rails 4.1

2015-04-26 Thread Colin Law
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

Re: [Rails] Hash is treated as string in Rails 4.1

2015-04-26 Thread tamouse pontiki
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

[Rails] Hash is treated as string in Rails 4.1

2015-04-26 Thread Gaohong Wei
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

[Rails] hash keys, symbolize_keys and sintrigify_keys

2015-04-17 Thread André Orvalho
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

[Rails] Hash Issue when looping through

2012-09-05 Thread Anthony Brushwood
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

[Rails] hash assignment (1.9.2)

2011-09-08 Thread AppleII717
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.

Re: [Rails] Hash each where

2011-06-30 Thread Michael Pavling
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?

[Rails] Hash each where

2011-06-30 Thread Sebastian
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

Re: [Rails] hash vs methods

2011-04-13 Thread Philip Hallstrom
> 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

[Rails] hash vs methods

2011-04-13 Thread John Merlino
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("

Re: [Rails] Hash objects not display properly

2011-02-25 Thread Colin Law
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

[Rails] Hash objects not display properly

2011-02-25 Thread Vijay Ra
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 ==

Re: [Rails] Hash to list fails

2011-02-15 Thread Jim Ruther Nill
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

Re: [Rails] Hash to list fails

2011-02-15 Thread Jim Ruther Nill
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

Re: [Rails] Hash to list fails

2011-02-15 Thread kedar mhaswade
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

Re: [Rails] Hash to list fails

2011-02-15 Thread Colin Law
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

[Rails] Hash to list fails

2011-02-15 Thread Paul Bergstrom
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

[Rails] Hash or not a Hash?!

2010-07-16 Thread Abder-Rahman Ali
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

Re: [Rails] hash string to symbol

2010-04-05 Thread Philip Hallstrom
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.

[Rails] hash string to symbol

2010-04-05 Thread Me
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

Re: [Rails] hash in controller is nil after submitting form

2010-03-18 Thread Colin Law
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

Re: [Rails] hash in controller is nil after submitting form

2010-03-18 Thread Michael Pavling
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

[Rails] hash in controller is nil after submitting form

2010-03-18 Thread ES
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"],

[Rails] hash to URL

2009-09-14 Thread Re Res
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

[Rails] Hash Problem .. + Urgent

2009-07-22 Thread Hemant Bhargava
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

[Rails] Hash#merge in a controller

2009-05-09 Thread Alberto Santini
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,

[Rails] Hash with key and value from ActiveRecord?

2009-03-25 Thread Heinz Strunk
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? -

[Rails] Hash and Array

2009-02-21 Thread Cyrus Dev
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

[Rails] Hash

2009-02-19 Thread Cyrus Dev
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/. --~--~-

[Rails] Hash names with white spaces

2009-01-30 Thread Stefano Bonomi
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

[Rails] Hash Sorting

2008-12-25 Thread Sunny Bogawat
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