Problems passing two sets of data

Ok I am going to try and explain this as best as I can. It seemed to
be a simple problem but is turning out to be alot more difficult then i
imagined.

I have a table of categories and a table of special requests and a
table of special request items. Special requests have many special
request items and special request items each belong to a category and
also has a interget field for count. Simple right?

So here is the problem. I want to display a form that display empty
text fields for each and every category that ask for the count for this
perticular special request item. All of the special request items with
a count of 0 or higher will be added to this newly created special
request.

relativly straightforward…

where i hit a wall is that these text fields have to communicate back
to the controller not only the count but also the category which they
are refering to and I ahvent a clue where to begin. Any insight into
this problem would be very helpful

Thanks in advance.
Keith

Keith:

If I get what you’re asking… you might do it this way… off the top
of my head, not tested, may need some ‘tweaking’…

In the controller that produces the form:
@categories = Category.find(:all)

each_with_index {|item, index|

In your view:

#normal form fields for special request

@categories.each_with_index do |c,i|
text_field_tag(“request_item[i][count]”,0)
hidden_field_tag(“request_item[i][category]”,#{c.id})
end

In the controller that processes the form:
params[:request_item].each do |ri|
special_request = SpecialRequest.new(params[:special_request])
special_request.special_request_items <<
SpecialRequestItem.new(‘count’ => ri[‘count’], ‘category_id’ =>
ri[‘cateogory’]) unless ri[‘count’].to_i <= 0
end

Essentially, you are creating many ‘sets’ of the same data (special
request items) in your form, identified by a unique key value (the [i]
part of the form field helper calls). This effectively creates an array
of these ‘sets’ of data, which you step through in your controller and
process accordingly.

c.

Keith wrote:

Ok I am going to try and explain this as best as I can. It seemed to
be a simple problem but is turning out to be alot more difficult then i
imagined.

I have a table of categories and a table of special requests and a
table of special request items. Special requests have many special
request items and special request items each belong to a category and
also has a interget field for count. Simple right?

So here is the problem. I want to display a form that display empty
text fields for each and every category that ask for the count for this
perticular special request item. All of the special request items with
a count of 0 or higher will be added to this newly created special
request.

relativly straightforward…

where i hit a wall is that these text fields have to communicate back
to the controller not only the count but also the category which they
are refering to and I ahvent a clue where to begin. Any insight into
this problem would be very helpful

Thanks in advance.
Keith

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs