Forum: Ruby on Rails Not sure where to begin updating a child table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
a.filipowski (Guest)
on 2005-11-22 22:12
(Received via mailing list)
I have a table that is defined as has_many and the child table is
defined as has_one. I can create new children with ease and do almost
everything else I want to do with it except for one thing. I have a
form and within that form I have text boxes to update a column in the
the children objects (multiple). In that same form I want to also
update columns and attributes of the parent. Does anyone have an
example to have a single button form that updates multiple tables/
models? Or can you point me to the right tutorial? Agile Web
Development mentions passing an array to the update method but there
is no example.

Thanks

Andrew
a.filipowski (Guest)
on 2005-11-22 22:56
(Received via mailing list)
To clarify here is some code that I have tried:

My controller has this action:

def update_radio_buttons
		@field = Field.find(params[:id])
		@field.update_attributes(:field_text => params[:field_text],
															:required => params[:required])
		for @value in @field.values
			value_text = ":valuetext_#{@value.id}"
			@temp = params[value_text]
     		@value.update_attribute(:value_text => @temp)
   		end
		# more stuff here
	end

view:

my view looks sort of like this (i condensed the partials and some of
the other stuff going on on the page to save some space here)

<%= form_remote_tag( :update => 'FieldDesignArea',
												:url => { :action => 'update_radio_buttons', :id =>
@field.id }) %>
			Field:<br/>
			<%= text_area_tag(:field_text, @field.field_text) %><br/><br/>
			Values:<br/>
			<div id="Values<%= h(@value.id) %>">
				<% for @value in @field.values %>
					<div id="Value<%= h(@value.id) %>">
	<input type="text" name="valuetext_<%= h(@value.id) %>" value="<%= h
(@value.value_text) %>">
</div>
			<% end %>
			</div>


The error that I get when I run this code after making a change is
the following:

wrong number of arguments (1 for 2)

and the parameters look like this:

Parameters: {"commit"=>"Udate", "valuetext_58"=>"huh",
"valuetext_71"=>"Choice", "id"=>"106", "required"=>"1", "_"=>"",
"field_text"=>"New Field Is here"}

So that is in a nut shell what I am trying to do. Any help would be
greatly appreciated.


Andrew
Jm M. (Guest)
on 2005-11-22 23:08
(Received via mailing list)
I copied a directory of views and noticed that the
Scaffold.CSS stylesheet didn't add to my pages. Is
there a way to manually link to a style sheet?







__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
vanek (Guest)
on 2005-11-23 16:17
(Received via mailing list)
<%= stylesheet_link_tag "your_css_stylesheet" %>
This topic is locked and can not be replied to.