Rails 3.1.3
I have tables, Video and Script having association,
Video 1 --- n Script
So, every Script needs the parent id, in this case, video_id.
If I simply create a new Script instance, the view renders as follows.
<%= render :partial => "new_script", :locals => { :script =>
Script.new(:video_id => @video.id)} %>
which works fine. Now I would like to develop further. The Script
objects may have already existed and if so, I want to update after
editing them.
So I tried,
<%= render :partial => "create_or_update_script",
:locals => { :script => Script.find_or_create_by_video_id(:video_id =>
@video.id)} %>
renders a partial,
<%= form_for script,
:url=>{:controller=>'scripts', :action=>'create_or_update'},
:remote => true do |f| %>
<%= f.hidden_field :video_id %>
<%= f.text_field :startp, :readonly => true %>
<%= f.text_field :text %>
<%= f.submit "create_or_update" %>
<% end %>
But this will set "Script id" to be "Video id", which are supposed to be
distinct from each other.
I assume the problem is the way I use "create_or_update".
Could anyone tell me where the problem is and hopefully the solution?
Thanks in advance.
soichi
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.