Displaying 20 results from an estimated 50000 matches similar to: "how do i use a loop to fill an array?"
2006 Jun 04
5
Creating pulldowns using loops
Creating looped pulldowns in PHP is simple so I can''t figure out why it
seems to elude me in RoR. I want to create a simple pulldown list with
the options and values "1" through "14."
I have been trying to accomplish this with the .upto method like so:
--START RHTML CODE--
<% options_array = [
1.upto(14) {|i| print "[" i "," i "]"}
2006 Apr 10
9
Pagination with letter (A B C D ... Z)
Hi there,
Is there a neat and easy way to implement pagination with letters
rather than numbers eg :
A B C D ... Z
Rob
2007 Jun 19
3
another issue with highlighting
Hi,
I''m encountering another highlighting issue.
(about the first one "range search and highlighting", i received no
response. I don''t even know if somebody tried to reproduce and/or if
it''s normal behavior)
about the new issue, an example will be easier for you to reproduce:
I''m filling an index with random data, i try to match for "*1*"
2006 Apr 05
7
select_tag - populating options
Hello,
I want to a select tag, where you can choose a number between 1 and 100.
My inital code is based on the examples from Agile Web Development with
Rails, and looks like this:
view:
<%= options = [["Select number of lines", ""]] + RfqLines::LINE_QTY
select("rfq_line", "line_qty", options) %>
model:
LINE_QTY = select_fill
def
2007 Jan 20
2
Conditional pluralize without the number
Hi.
Assume you have an array of person names. I want to generate results in
my view that look like this:
Abby is your friend
or
Abby, Bob, and Carol are your friends.
So I''d like to say:
<%= friends.to_sentence %>
<%= pluralize(friends.count, "is") %>
your <%= pluralize(friends.count, "friend") %>
But because pluralize puts in the
2009 Jul 29
2
LoadError: RubyGem version error: rake-compiler(0.6.0 not
i tried running the following from commands for creating a class Story
and instance of class called story in Rails script console. (pg
102/103 from Simply Rails 2 book. P. Lenz) I get the following error:
Gem::LoadError: RubyGem version error: rake-compiler(0.6.0 not ~> 0.5.0)
I do not see any environment variables or version numbers I can make
changes to to get RubyGem upto date.
I have
2006 May 27
3
Saving an Array to MySQL... data changes...
I have a multiple select menu:
<%= select_tag ''resume[employer_1_industry][]'',
options_for_select(industries_helper, @resume.employer_1_industry),
:multiple=> true %>
It produces this HTML:
<select id="resume[employer_1_industry][]" multiple="multiple"
name="resume[employer_1_industry][]">
<option value="">-
2007 Nov 29
3
Strange Array behaviour
I''m having a strange thing when using the Enumerable extensions for
Rails:
Have a look at the following code:
class Invoice < ActiveRecord::Base
has_many :invoice_lines
def total
invoice_lines.sum(&:total)
end
end
class InvoiceLine < ActiveRecord::Base
belongs_to :invoice
def total
amount * price
end
end
Now, when calling invoice.total, I get wrong
2006 Mar 12
2
Find all the methods on a object in an irb session?
How can I find all the methods on an object from withing irb?
Thanks,
Joe
2009 Jan 31
9
Maxima and Ruby Integration
I''m looking to write a javascript heavy clientside program with a
something serverside backend that connects to the free maxima math
program. I have extensive knowledge of ruby on rails, so I would prefer
to call Maxima with ruby, but I don''t know if this is even possible. Its
fairly easy to call Maxima (with a lisp implementation) using ANSI C, it
is a little less easy to
2006 Nov 29
6
How do I create an array to represent an empty record?
Here''s something that''s a snap to do in desktop database management
systems (like Paradox or Access) but I haven''t figured out how to do it
in RoR, and can''t seem to find any examples by googling, etc.
My overall goal is to create a temporary space in which to create and
process a single new record (representating a payment transaction), and
when I''m
2006 Jun 23
2
Storing Array in Database
Hey all,
I''m storing an array of timestamps in a field in my database as an
array. When the items get saved, however, some minus signs are appended
to the text:
sample output:
---
- 1151971200
- 1152576000
- 1153180800
- 1153785600
- 1154390400
Is this normal behavior? When I retrive the value out of the database
and .to_a, the three minus signs (---) are counted as the first
2008 Oct 07
6
Hpricot loop question to read table row values
Hi.
I''ve got a file that contains a table that looks like this:
<table>
<tr><td>column title a</td><td>column title b</td></tr>
<tr><td>row 1 a</td><td>row 1 b</td></tr>
<tr><td>row 2 a</td><td>row 2 b</td></tr>
<tr><td>row 3 a</td><td>row 3
2011 Feb 27
10
How to store the same key multi times in a Hash ?
given an Arra tags[]
I need to produce a resulting Hash as following ..
{ "$in" => [tags[0]], "$in" =>[tags[1], ...}
in which the key should be always the same and the value being an
Array
I tried this :
myHash = {}
tags.each do |tag|
h = {"$in" => [tag]}
myHash.merge!(h)
end
but the merge! is only
2006 Apr 25
1
Array of dates/times from time.now till nextweek
Hi,
I would like to make @dates in my controller.
I tried the following:
startdate = Time.now
enddate = startdate.next_week
for enddate > startdate
@dates << startdate
startdate = startdate.tomorrow
end
But I get an errormessage when I check the syntax:
"warning: useless use of a variable in void context"
Anyone?
Thanks!
Steven.
--
Posted via
2007 Nov 07
7
Help on loop
Hey,
I have got a script that returns a long list of font family names, which
I all want to store in a variable (array). I tried doing this with @f =
font.family also in the for loop below but it only prints the last item
when I want to display the results.
require ''rubygems''
require ''RMagick''
include Magick
for font in Magick.fonts
puts font.family
end
2007 Nov 20
9
Testing Models without fixtures
Hi,
I would like to test a sorting method that is in the user model, it''s
a class method called search.
What I would like to do is create 2 users and load the test database
with just those 2 users, so that I can call
User.search("john") and it would return those two users.
Not sure how to clear the test database and populate it just with
these 2 users for that specific
2006 May 18
3
populating array of text_fields from an array of model objects
I have in my view the following:
<% 0.upto(@num_performances) do |idx| -%>
<%= text_field ''performance'', ''city'', :index => idx, %>
<%= text_field ''performance'', ''venue'', :index => idx, %>
<% end -%>
and in my controller I have:
@performance = [Performance.new("city" =>
2009 Jan 20
2
Do I need an SSL certificate to use ActionMailer 2.2.2?
Hi guys - I''m sorry to post about this issue again but after several
days I still cannot get ActionMailer working and I''ve been through
every tutorial/forum looking for the answer.
I know ActionMailer now requires SSL validation, does that mean I need
to purchase an SSL certificate before I can send emails?
If not, is there anyone out there who can help me set up my mailer to
2009 Jan 22
4
Is there a plugin that can autofill(ajax) during user input?
I haven''t done rails in a year, but can someone tell me if there is a
plugin or how much work is it to add an auto fill function like google''s
front page?
Would you just use an observer on the form or is there already a built
in class that can do this?
Thanks!
Feng
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received