Rails 3.1.3
I have Video, Script classes having
Video 1----0…n Script
association.
in “Video” show.html.erb, there are both
<%= render :partial => “new_script”,
:locals => { :script => Script.new(:video_id => @video.id)} %>
and
<%= render :partial => "script_list", :locals => {:scripts =>
@video.scripts} %>
in other words, a single page contains a video clip and “script” create
form as well as the list of all “scripts” that belong to that video.
My question is :
How can I stay in that page even after clicking the save button for a
new script?
And How can I update the “Script” list in the Video page using ajax?
Originally, scaffold generated
def new
@script = Script.new
respond_to do |format|
format.html
format.json { render json: @script }
end
end
As all of you are aware, this method redirect_to Script “show” page. I
tried for “_new_script.html.erb” partial, I added
<%= link_to 'SAVE', {:controller => 'scripts', :action => 'new' },
and for scripts_controller.rb
respond_to do |format|
format.html { redirect_to :video } #changed HERE
format.json { render json: @script }
end
But does not do the job.
jQuery is working properly, so the problem of ajax part is just coding.
Could anyone help me out?
Thanks in advance.
soichi