Jan:
Thanks again! Actually, after some prodding, I did get it to work -
turned out it needed a "fieldset" link , which I found in agile rails
dev book. I'm so close, and I know the problem I'm having now is a
function of being a newbie. My problem is that I can get the product
id into the tags table, but for some reason the tag itself isn't being
automatically saved by rails. Here's what I've got (BTW: I used
"product" as the parent becuase that's what everyone uses. In reality,
it's "goals"), here's new & create methods from goals
goals_controller.rb:
def new
@goal = Goal.new
@goal_tag = GoalTag.new
fk_timeperiod #to get fk for another field
fk_goaltype #to get fk for another field
end
def create
@goal = Goal.new(params[:goal])
@goal_tag = GoalTag.new(params[:g])
Goal.transaction do
@goal_tag.goal_id = @goal
@goal_tag.name = ??? ##THIS IS WHERE THE PROBLEM IS
@goal.save!
@goal_tag.save!
flash[:notice] = 'Goal was successfully created.'
redirect_to :action => 'show', :id => @goal
end
rescue ActiveRecord::RecordInvalid => e
@goal_tag.valid? # force checking of errors even if products
failed
render :action => :new
end
here's the tags partial: (view/goal_tags/_form.rhtml)
<fieldset>
<legend>Tags...</legend>
<p><% fields_for :goal_tags do |g|%>
Enter Tags for this Goal (comma seperated)<br>
<%= g.text_field :name %>
<% end %></p>
</fieldset>
this partial is just rendered inside the "new"rhtml for the goal(former
product):
/views/goals/new.rhtml
<h1>New goal</h1>
<%= start_form_tag :action => 'create' %>
<%= render :partial => 'form' %>
<%= render :partial => '/goal_tags/form' %> #HERE HERE
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', :action => 'list' %>
Now just in case you need it, here's the goals _form partial:
<%= error_messages_for 'goal' %>
<!--[form:goal]-->
<p>
<label for="goal_goal_name">Goal name</label><br/>
<%= text_field 'goal', 'goal_name' %>
</p>
<div class="auto_complete"
id="goal_goal_name_auto_complete" ></div>
<%= auto_complete_field :goal_goal_name,
:url=>{:action=>'autocomplete_goal_name'}, :tokens => ',' %>
<table>
<tr>
<td><label for="goalhist_goaltype_id">Goal Type</label></td>
<td><label for="goalhist_timeperiod_id">Timeperiod</label></td>
<td><label for="goal_public">Public</label></td>
</tr>
<tr>
<td><%= collection_select 'goal', 'goaltype_id', @all_gt, :id,
:goaltype %></p></td>
<td><%= collection_select 'goal', 'timeperiod_id', @all_tps, :id, :name
%></td>
<td><select id="goal_public" name="goal[public]"><option
value="false">False</option><option
value="true">True</option></select></td>
</tr>
</table>
<br>
<!--[eoform:goal]-->
So, as you can see from above, that is where the problem is, I can
committ the goal_id but not the name of the tag itself!!! The fact
that rails isn't handlign this automatically is what prompted me to
force it in the line in the create method with ??? in the controller
above. What am I missing?
Again, thank you so much for your help and your prompt reply!
Mike