Hi again.
I would like to pass an instance variable to "HERE!!!" in 'save.js.erb'
$('#listtrans').html(
'<%= escape_javascript(render :partial => "videos/script_list",
:locals => { :scripts => Script.find_all_by_video_id(HERE!!!) } ) %>
');
If I put a specific value, video_id, (18 in this case ) like
$('#listtrans').html('<%= escape_javascript(render :partial =>
"videos/script_list", :locals => { :scripts =>
Script.find_all_by_video_id(18) } ) %>');
works fine. Of course, this must be generalized.
So I tried,
$('#listtrans').html('<%= escape_javascript(render :partial =>
"videos/script_list", :locals => { :scripts =>
Script.find_all_by_video_id(<%= @video.id %>) } ) %>');
gives an error
ActionView::Template::Error
(/Users/ishidasouichi/Dropbox/Rails/script_youtube/app/views/videos/save.js.erb:3:
syntax error, unexpected '<', expecting ')'
...> Script.find_all_by_video_id(<%= @video.id );@output_buffer...
Also, I tried
@video.id
params[:video_id]
and so on.
Any idea?
Thanks in advance?
soichi
--
Posted via http://www.ruby-forum.com/.
$('#listtrans').html('<%= escape_javascript(render :partial =>
"videos/script_list", :locals => { :scripts =>
Script.find_all_by_video_id(@video.id) } ) %>')
Started POST "/scripts" for 127.0.0.1 at 2012-02-16 15:53:50 +0900
Processing by ScriptsController#create as JS
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"9rMiPwxlQrXiAIgUy8Qqe77KXDezXmpLF4WLupZb5ME=",
"script"=>{"video_id"=>"18", "startp"=>"85", "text"=>"korejyadamedann"},
"commit"=>"save"}
(0.1ms) SELECT 1 FROM "scripts" WHERE "scripts"."startp" = 85 LIMIT
1
SQL (0.7ms) INSERT INTO "scripts" ("created_at", "startp", "text",
"updated_at", "video_id") VALUES (?, ?, ?, ?, ?) [["created_at", Thu,
16 Feb 2012 06:53:50 UTC +00:00], ["startp", 85], ["text",
"korejyadamedann"], ["updated_at", Thu, 16 Feb 2012 06:53:50 UTC
+00:00], ["video_id", 18]]
Rendered videos/save.js.erb (1.5ms)
Completed 500 Internal Server Error in 138ms
ActionView::Template::Error (Called id for nil, which would mistakenly
be 4 -- if you really wanted the id of nil, use object_id):
1:
2:
3: $('#listtrans').html('<%= escape_javascript(render :partial =>
"videos/script_list", :locals => { :scripts =>
Script.find_all_by_video_id(@video.id) } ) %>');
4:
5:
6:
app/views/videos/save.js.erb:3:in
`_app_views_videos_save_js_erb__2673251445733535399_2157206780'
app/controllers/scripts_controller.rb:47:in `block (2 levels) in
create'
app/controllers/scripts_controller.rb:43:in `create'
Does anyone know why?
Did you read the error? Google it?
> ActionView::Template::Error (Called id for nil, which would mistakenly
> be 4 -- if you really wanted the id of nil, use object_id):
>
> 3: $('#listtrans').html('<%= escape_javascript(render :partial =>
> "videos/script_list", :locals => { :scripts =>
> Script.find_all_by_video_id(@video.id) } ) %>');
>
> app/views/videos/save.js.erb:3:in
>
> Does anyone know why?
It's most likely that @video (the instance variable you want the id
of) is nil. Use debugging techniques to break into the code where it's
being set and being used to inspect it.
So I hoped someone can guess from my writing but I realized the
importance of debugger now.
Thanks anyway. I will come back when the debugger problem is resolved.
sochi
You _can_ debug using "puts".... it's can just be painful and slow to
resolve issues (although you could've sorted this problem with it
quite fast ;-)
Thanks. To be honest, I was having the 'installing debugger' problem as
well ;)
It seems many people have the same problem in installing ruby-debug19.
So I hoped someone can guess from my writing but I realized the
importance of debugger now.
Thanks anyway. I will come back when the debugger problem is resolved.