Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: nicole kelly
RE: new action doesn't save my child [ reply ]  
2007-07-20 17:56
Did you get any resolution to this problem? I'm having a similar issue - only mine comes with errors! I can save my parent if I don't add any children to my new view (which makes use of the sublist plugin) but if I add any of my sublist items i get an error like this:

undefined method `stringify_keys!' for "1":String

any ideas?

my controller code looks like this:
def create
@project = Project.new(@params[:project])
success = true
success &&= initialize_tasks
success &&= @project.save
if success
flash[:notice] = 'Project successfully created.'
redirect_to :action => 'list'
else
prepare_tasks
render_action 'new'
end
end

By: dale baker
RE: new action doesn't save my child [ reply ]  
2007-05-12 07:34
I found my problem. I accidentally set my form's action to go to the new rather than the expected create action. This is my first RoR project. Now it's working perfectly. Thanks a million for your responsiveness in helping me through this. Cheers.

By: yossarian dunbar
RE: new action doesn't save my child [ reply ]  
2007-05-11 15:37
Hey, sorry for not getting back to you earlier, I downloaded your code and then got pulled into a meeting at work.

My guess is that your view action doesn't contain proper targeting information for the controller to pick up and save automatically.

As an example of what I mean, I've got a sub_list that displays links for an article. I've split out the link editor stuff into a partial called _link.rhtml, the contents of which are:

<% @link = link %>
<div id="<%= "link_#{link.id}" %>">
<fieldset>
<label class="first" for="link[]_item_id">
Link
</label><br/><br/>
<label for="link[]_title">
Title*<br/>
<%= text_field 'link[]', 'title', :size => 30 %>
</label><br/><br/>
<label for="link[]_url">
URL*<br/>
<%= text_field 'link[]', 'url', :size => 30 %>
</label><br/><br/>
<label for="link[]_description">
Description<br/>
<%= text_area 'link[]', 'description', {:cols => 30, :rows => 3} %>
</label><br/><br/>
<%= sub_list_remove_link link, 'Link', 'Del' %>
</fieldset>
</div>


It's been a while since I wrote this, but if I remember correctly, all that link[] and link_#{link.id} stuff is what gives the controller the ability to automatically find and persist sub_list content coming from the form.


By: dale baker
RE: new action doesn't save my child [ reply ]  
2007-05-10 21:04
I mean I manually saved the child in the "new" action. Like so...

if request.post?
if @interview.save
params[:paragraph].each { |p|
p[1]["interview_id"] = @interview.id
@paragraph = Paragraph.new(p[1])
@paragraph.save
}
redirect_to :action => 'list'
else
render_action 'new'
end
end

By: dale baker
RE: new action doesn't save my child [ reply ]  
2007-05-10 21:01
Well I ended up just manually saving the paragraphs in the create action. And that seems to work fine.

By: dale baker
RE: new action doesn't save my child [ reply ]  
2007-05-10 13:33
Seems like there is only two lines in the view (besides the javascript includes in the layout).

But if I may be so bold as to post my view code as well....

<tr>
<td>
<span id="label5">
<b><u>Paragraphs</u></b> &nbsp; &nbsp; <%= sub_list_add_link 'Paragraph', '[Add New Paragraph]' %>
</span>
<br>
<%= sub_list_content 'Paragraph', 'interview' %>
<!--
<% unless controller.action_name == 'show' %>
<%= sub_list_remove_link 'paragraph', 'Paragraph', 'Del' %>
<% end %>
-->
</td>
<td>
</td>
</tr>

In fact, if it's useful to see more than excerpts, I'm happy to zip up my whole app directory to peruse. And at the risk of being too presumptuous, it's available here for a time. http://www.kerkim.info/etnoapp.zip
Thanks for your help.

By: yossarian dunbar
RE: new action doesn't save my child [ reply ]  
2007-05-10 09:40
Hey,

Your controller code looks fine to me, maybe there's something wrong with the form code in the view?

By: dale baker
new action doesn't save my child [ reply ]  
2007-05-10 09:29

Everything seems to be working right in my new.rhtml, *except* the children (which are paragraphs in my excerpt below) don't end up being saved.

My code:

def create
@interview = Interview.new(@params[:interview])
success = true
success &&= initialize_paragraphs
success &&= @interview.save
if success
flash[:notice] = 'Paragraph successfully created.'
redirect_to :action => 'list'
else
prepare_paragraphs
render_action 'new'
end
end

Any ideas for me?