Displaying 20 results from an estimated 35 matches for "each_pair".
2012 Mar 28
4
Hash iteration order in a template not consistent
...= {
''/foo/'' => ''/home/foo/www/'',
''/bar/'' => ''/home/bar/www/'',
''/baz/'' => ''/home/baz/www//''
}
Then, in a template, I have:
<% aliases.each_pair do |key, val| -%>
Alias <%= key %> <%= val %>
<% end -%>
The result is mostly what I expect, but every once in a while, the order
in which the Aliases are generated from the ''each_pair'' loop changes,
resulting in a different file.
The Ruby do...
2006 May 25
3
Storing BigDecimal in the db
...-14 decimal places, so I''m
using BigDecimal. How can I store this in a db? I''m using postgresql
8.1.0, if that matters at all. I found a plugin [1] but it gives me
the error "You have a nil object when you didn''t expect it! The error
occurred while evaluating nil.each_pair," with no line number. The
plugin itself never calls #each_pair, so it has to be somewhere inside
Rails or the postgres adapter. I''m using Rails 1.1.2 and the postgres
0.7.1 adapter.
Pat
2006 Apr 16
3
variable variables?
Hi everyone,
Does Ruby support variable variables like PHP
(http://www.php.net/manual/en/language.variables.variable.php)? Or do I have
to use eval, like
some_hash.each_pair{|key, pair|
eval "#{key} = #{value}"
}
Or is there some other way?
I''m actually trying to figure this out in order to use ez_where to create
its conditions from a hash, so if this isn''t even necessary could someone
let me know?
Thanks,
Daniel
2011 Jan 20
4
Comment.all returns array of what?
...nt.all
@comments is an array.
I can for example access comment.created_at directly, or I could do:
<% @comments.each do |comment| %>
<%= debug comment["created_at"] %>
<% end %>
I expected comment to be a hash, but comment.keys or comment.values fail, as
well as an each_pair approach.
[I was actually trying to do a debug output printing all columns and columns
names]
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0...
2005 Dec 21
2
ActiveRecord Error with << in Collection
...{RAILS_ROOT}/app/controllers/cmdb_controller.rb:24:in `new''
#{RAILS_ROOT}/app/controllers/cmdb_controller.rb:24:in `create''
=============== Controller =================
def create
@ci = ConfigurationItem.new(params[:ci])
if(params[:attribute_id])
params[:attribute_id].each_pair{ |attr_id, |attr_value_id|
attribute = ConfigurationItemAttributeValue.new
attribute.attribute_id= attr_id
attribute.value_id= attr_value_id
@ci.attributes << attribute
}
end
if(params[:attribute_value])
params[:attribute_value].each_pair{ |attr_id, |attr_value|...
2008 Jul 10
6
Uppercase all row columns
Hi.
I have to convert the contents of all columns to uppercase before
creating a row. Is there an easy way to accomplish this so I don''t
have to go one column at a time and upcase! it?
Thanks.
Pepe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group,
2007 Dec 28
11
LIKE clause in rails
Hello,
I am trying to achieve a search functionality in the following manner
i have an table called people
which has
first_name,last_name,etc...
After the user form to search people is submitted i get the params hash
as params[:persons]={"first_name"=> "%John%","last_name"=>"%Stevens%"}
NOTE : I have changed the params hash to include the %.
Now
2010 Oct 21
1
SLES11 facter problems
...ed
constant Facter::IPAddress (NameError)
After that I tried commenting lines 17-46 from /usr/lib64/ruby/
vendor_ruby/1.8/facter/ipmess.rb but to no avail:
# facter
/usr/lib64/ruby/gems/1.8/gems/facter-1.5.8/lib/facter/util/
manufacturer.rb:36:in `dmi_find_system_info'': undefined method
`each_pair'' for "Type:":String (NoMethodError)
Is this a known bug?
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email...
2012 Jul 05
1
hash to_yaml in erb template not giving valid yaml
...%= scope.to_hash.reject { |k,v| !(
k.is_a?(String) && v.is_a?(String) ) }.to_yaml %>"),
#content => inline_template("<%= { \"a\" => 1, \"b\"=> 2}.to_yaml %>"),
content =>
inline_template("<%= facts = {}; scope.to_hash.each_pair {|k,v|
facts[k.to_s] = v.to_s unless k.to_s =~
/pkg_|_hours|_seconds|memoryfree|plugin_|config|_timestamp/ };
facts.to_yaml.sort %>"),
}
After a run the content is indented with 2 spaces and some facts give
me garbage values. If I verify this on e.g. http://yamllint.com/ I
have a syntax...
2010 May 13
6
to "loop through" the instance variables of ActiveRecord?
to wrap each instance variable of an ActiveRecord object between "<td>"
and "</td>", is there a way to "loop through" them, at least in the
debug mode, no matter there is getter methods to get them or not, or at
least the ones with the getter methods?
Such as
<% @stories.each do |s| %>
<%= "<tr>" %>
<% s.each_property
2006 Mar 06
2
Cookies & gsub ?
I''m looking to store the current params into a/some cookie(s).
This works:
@params.each_pair do |this_index, this_param|
cookies[this_index] = this_param
end
Except, I get session-only cookies. This doesn''t work:
@params.each_pair do |this_index, this_param|
cookies[this_index] = {
:value => this_param,
:expires => 30.days.from_now
}
end
Specifcally,...
2008 Mar 12
3
Some random rails, and maybe Ruby, questions..
Hi,
I''m attempting to create a users statistics controller, and have saved
up some questions regarding this for this post.
So, please comment on any one of them, if not all :-)
1) Is there a library somewhere for doing stats? (e.g. mean, median,
sd, skewness..) on an array in rails?
2) What library would you recommend for "publication ready" (i.e. not
cheesy) histograms,
2006 Mar 02
6
Newb question about facade columns
Hello,
I am trying to deal with a database table that contains a date in the
form of the number of seconds since epoch. Data is inserted in this
format by an existing script that I can''t change, so a schema change
isn''t realistic.
I would like to allow humans to view and edit this data in the form of
an actual human-readable date. I figured a facade column would be the
2006 Mar 09
3
Need help PLEASE!!! - updating collection from form
Greetings!
I''m trying to update a set of records from the same model on one form. The AWD book gives an example on p.356 but I guess I''m not understanding it.
I can see from the error message I''m getting that the controller is receiving a hash of hashes back from the view, and that it''s got the stuff I expected (two values per record that was sent to the
2006 Jul 12
12
pass hash as parameter
Hello,
How can I pass a hash as parameter from a template with url_for?
e.g. : if I have
test = { :a => "a", :b => "b" }
How can I pass that with my request? Is it possible to pass nested
hash''es to?
Right now,
url_for :action => :test, test
doesn''t seem to work.
Thank you,
--
2006 Nov 04
0
arrayfields-3.6.0
...p list[''a''] #=> 0
p list[:a] #=> 0
3.5.0:
- added more hash-like methods
- update
- replace
- invert
3.4.0:
- added FieldedArray[] ctor
- added methods to make Arrays with fields set behave more closely to Hashes
- each_pair
- each_key
- each_value
- fetch
- has_key?
- member?
- key?
- has_value?
- value?
- keys?
- store
- values
3.3.0:
- added gemspec file - thnx Assaph Mehr
- added FieldedArray proxy class which minimizes modif...
2006 Mar 27
0
render_to_string troubles
...ller:
# handle all regeneration of pages - available to all controllers
def rebuild_page(options, path = nil)
# get rid of the existing one
expire_page(options)
# pull the page in as a string
# set page parameters first:
if options.has_key?(:params)
options[:params].each_pair {
|key, value|
@params[key] = value
}
end
page = render_to_string(options)
# write the rendered content to the right place
cache_page(page, options)
end
I can see the parameters have been set, but somehow the ''page'' parameter never gets...
2005 Sep 07
0
model constructor errors.
...e a model; I do photo = Photo.new(parameters) parameters
contains: {"picture"=>#<File:C:/DOCUME~1/BART~1/LOCALS~1/Temp/CGI3180.1>}
so i expect that the def picture=(filename) method is called in this
constructor.. this is not the case. Does anyone know why?
params[:photo].each_pair do |id, parameters|
photo = Photo.new(parameters)
end
class Photo < ActiveRecord::Base
attr_accessor :file, :content_type, :size, :extension, :local_path, :destroyed
attr_reader :original_filename
attr_accessible :title, :description
has_many :comments, :exclusively_de...
2010 Mar 03
0
Using gsub to replace text with link from database
...nal_name, i|
@full_text.gsub!(original_name.to_s, @new_link_array[i])
end
results = @full_text.scan(/([A-Z]+[a-zA-Z]* [A-Z]+[a-zA-Z]*)/)
names_links = {}
results.each do |name|
unless names_links[name]
names_links[name] = method_to_construct_link_for_name(name)
end
end
names_links.each_pair do |name, link|
@full_text.gsub!(name, link)
end
The results are not consistent. I was wondering if somebody could help
me out.
-A
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
T...
2006 Apr 14
2
spot the error (I can''t, I''m new)
I have a form that I want to use to update multiple
objects. In the controller,
@grades = Grade.find(params[:grade].keys)
@grades.each_with_index do |grade, i|
grade.update_attribute(params[:grade][i])
end
all_valid = @grades.inject(true) {|memo, c|
c.valid? && memo }
this doesn''t update the attributes as I would expect.
(I would just use