Displaying 20 results from an estimated 3000 matches similar to: "Problem with select and each_with_index"
2006 May 12
1
each_with_index. Can you start at a desired index position?
When using array.each_with_index how do you start at a desired index
position?
I can do it like this, but its not very clean and doesnt seem efficient
:
desired_index_start = 20
array.each_with_index do |value,index|
next if index<desired_index_start
end
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2006 Mar 04
5
has_many and belongs_to example?
Hi!
If i have 2 tables i.e. product and images and product has_many images,
image belongs_to product - how to create _form.rhtml, new/create and
edit/update methods in product controller, so in a single form i can add
one product and MANY (let''s assume for now that this number is fixed)
images for this product?
Pleeeeease help me :)
--
Posted via http://www.ruby-forum.com/.
2010 Apr 11
2
everything seems to hang, but system is idle?
Hi All,
My one server recently started acting very weird. At fist I couldn't
import any images with cobbler as rsync crashes the whole time. I was
told to ask on the cobbler list (maybe it's not supported here?) but I
left it at that (subscribed to far too many lists already).
Yesteday I wanted to copy some stuff from a USB disk to the server
(using rsync to update the files which have
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" =>
2008 Jul 08
12
Some more win32-security: SID.create
Hi all,
How does this look as a general approach to a SID.create method:
# Creates and initializes
def self.create(authority, *sub_authorities)
if sub_authorities.length > 8
raise ArgumentError, ''maximum of 8 subauthorities allowed''
end
authorities = Array.new(8, 0)
authorities.replace(sub_authorities)
count = authorities.select{ |e| e > 0 }.size
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
2011 Dec 17
2
help me....
Life times of one brand of light bulb were observed. Life hours of nine light
bulbs were 898, 720, 354, 405, 620, 54, 229, 306, 890. There were three more
light bulbs that were still burning after 1000 hours. It is common to assume
the life time of a light bulb follows an exponential distribution. With the
observed data find the MLE of the parameter of the exponential distribution
with EM
2005 Sep 05
4
Dummy variables model
Hi, all!
Anyone know an easy way to specify the following model.
Panel dataset, with stock through time, by firm.
I want to run a model of y on a bunch of explanatory variables, and one
dummy for each firm, which is 1 for observations that come from firm i,
and 0 everywhere else. I have over 200 firms (and a factor variable that
contains a firm identifier).
Any easy way of going about
2006 Apr 03
2
Fast way of finding new position for model object?
I have a model object that acts as a list. The position of each object
is determined by two factors: number of votes ascending and age of
object descending. When a user adds or deletes a vote I need to
quickly update the associated model object''s position. Right now this
is done with the following method:
def update_position
position = nil
Bug.find(:all, :order =>
2009 Jul 16
9
Please help me understand how arrays are translated in rails
I''ve spent hours researching the subject and have tried many test
sequences in IRB, and rails console but I''m just having trouble making
headway into what is probably a very easy subject.
I understand arrays with at least 4 other languages but with Ruby I
haven''t found a mental connection with how I can assign variables to
arrays..
Take for example:
def
2006 Apr 19
2
Ferret EOFError creating index
I''ve been messing around with Ferret (no punn intended). After spending
some time testing it out (indexing to file), I decided to index about
10% of the data I want to eventually index. It took several hours to
complete the index on my local machine, but it was created without any
problems and after optimising it the searches returned results at the
sort of speed I was expecting. I
2006 May 23
1
Nut issue or MGE issue?
Hi,
I took the advice of Daniel O'Connor, found out what variables I
had available to me, and put them in the conf. So now it looks like :
[ellipse]
driver = mge-shut
port = /dev/cuaa0
desc = "UPS"
lowbatt = 5
offdelay = 120
let the UPS charge up fully, 24 hours.
I plugged a single lamp into it, with a 60W bulb.
At 3:40p
2007 Apr 18
2
Checking validity of NHS numbers
Hello
I need to check that the NHS numbers in my database are valid. I''m
storing them as ten-digit strings: the first nine are the identifier and
the tenth is a check digit.
There are four steps to calculating the check digit (from
http://www.connectingforhealth.nhs.uk/systemsandservices/nsts/docs/tech_nn_check_digit.pdf):
1. multiply each of the first nine digits by a weighting factor
2011 Dec 07
4
what is "private method `split' called for nil:NilClass" error??
Dear all,
I have this line:
<% $c_repo.split('','').each_with_index do |repo, i| %>
in one of my template files and on the target node I''m getting this
error:
err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Failed to parse template zmfs/zmfs_prob.erb: private method
`split'' called for nil:NilClass
Any idea what am I missing?
2006 Jan 02
2
Getting Index When Using render :partial
I''m using a web service to retrieve an array of results to a search
and a render :partial to display those results to the user, while at
the same time putting the results into the session. Is there a way
for my _book.rhtml file to have access to the index of the result
currently being displayed, like each_with_index makes available to
its block? This would allow me to have the
2006 Aug 24
3
A new QueueWorker class
Hello all,
I''ve come up w/ a worker class that manages queued jobs using a fixed
number of child workers. Well, that''s not quite true -- a new worker is
spawned for each job, but you set the total number that may exist at once.
There are three components:
1) queue_worker.rb: The singleton worker that manages the child workers.
You probably want to auto start this. Make sure you
2008 May 21
2
Schedule write errors?
My BackgrounDRb server intermittently bails out with the following exception
in the middle of a long running task running on a Worker sub classed
from BackgrounDRb::MetaWorker (the point at which it raises this exception
is different each time it runs)
/opt/local/lib/ruby/gems/1.8/gems/packet-0.1.5/lib/packet/packet_core.rb:145:in
`schedule_write'': You have a nil object when you
2011 Oct 10
6
Ruby on Rails sqlite3 ranking
I am making a browser-based game using ruby on rails and I am having
trouble implementing a ranking system for my game. Each player has
five skills: intelligence, creativity, strength, charisma and
technological. I want the player to have a rank for each skill. The
ranking I have in place right now gives the same rank if two players
have the same amount of skill.
SELECT COUNT(*) AS [rank] FROM
2006 Jul 20
11
3 columns
Hi all,
Not really sure what to put in the title so hope people still open this!
What I want to do is produce something like this
Col1 Col2 Col3
data1 data2 data3
data4 data5 data6
data7 data8 data9
data.. data.. data..
data.. data.. data..
data-n data-n+1 data-n+2
I can get the data back from my db
2006 Apr 12
4
Binding Text Field/Areas to Array?
Hi,
If I have @answers in my Controller, which is an array of Answer model
objects which don''t exist in the DB yet...
How do I bind a text_area helper in the View to each Answer? (I''m
pre-filling some of the Answers with other data people need to verify
before submitting and will insert on POST.)
I''ve been able to get the textareas to render but not with the