Rails 3.1.3

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/.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Michael Pavling at Feb 16, 2012 at 6:42 am

    On 16 February 2012 05:09, Soichi Ishida wrote:
    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(@video.id) } ) %>')

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Soichi Ishida at Feb 16, 2012 at 6:56 am
    Thanks for your answer but it give the error


    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?

    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Michael Pavling at Feb 16, 2012 at 8:20 am

    On 16 February 2012 06:55, Soichi Ishida wrote:
    Thanks for your answer but it give the error
    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.

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Soichi Ishida at Feb 16, 2012 at 9:49 am
    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.

    sochi

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Michael Pavling at Feb 16, 2012 at 9:52 am

    On 16 February 2012 09:49, Soichi Ishida wrote:
    Thanks. To be honest, I was having the 'installing debugger' problem as
    well ;)
    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 ;-)

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Peter Vandenabeele at Feb 17, 2012 at 11:52 pm

    On Thu, Feb 16, 2012 at 10:49 AM, Soichi Ishida wrote:

    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.
    For getting ruby debugger to work in 1.9.3 with Rails Gemfile, I got it
    working,
    but was quite some sweat ...

    http://rails.vandenabeele.com/blog/2011/12/21/installing-ruby-debug19-with-ruby-1-dot-9-3-on-rvm/

    I just checked now, and it see the latest version of linecache19 is still
    0.5.12
    (and the debugging only works with linecache 0.5.13). Probably a similar
    problem with ruby-debug-base19 being 0.11.25 but needs to be 0.11.26 .

    HTH,

    Peter

    --
    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Soichi Ishida at Feb 18, 2012 at 6:00 am
    Thanks. Finally ruby-debug19 is working for me. It took me a long time
    ;)

    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • CavalryJim at Feb 18, 2012 at 1:43 pm

    On Feb 15, 11:09 pm, Soichi Ishida wrote:
    Rails 3.1.3

    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
    Check out the gem 'gon' along with Ryan Bates' recent RailsCast on the
    topic of passing variables to JavaScript.
    $('#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 viahttp://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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Soichi Ishida at Feb 20, 2012 at 1:13 am
    Thanks. It will help!

    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 rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Minh Quy at Sep 17, 2013 at 6:10 am
    you should not use js with erb, it meet serious problem when you change
    variable rails without change js. You can use client variable gem, checkout
    more details https://github.com/Coffa/client_variable
    On Thursday, February 16, 2012 12:09:47 PM UTC+7, Ruby-Forum.com User wrote:

    Rails 3.1.3

    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/.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a5751bb6-8895-4c85-84c1-771ca9e66e1a%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tamara Temple at Sep 17, 2013 at 6:38 pm
    Not as old a message as I've responded to, but this one was from February of 2012…
    On Sep 16, 2013, at 9:26 AM, Minh Quy wrote:

    you should not use js with erb, it meet serious problem when you change variable rails without change js. You can use client variable gem, checkout more details https://github.com/Coffa/client_variable

    On Thursday, February 16, 2012 12:09:47 PM UTC+7, Ruby-Forum.com User wrote:
    Rails 3.1.3
    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/.

















    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a5751bb6-8895-4c85-84c1-771ca9e66e1a%40googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/BDBF0DF2-41BF-48A4-B9BE-E7F2FE2CE561%40gmail.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 16, '12 at 5:10a
activeSep 17, '13 at 6:38p
posts12
users6
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase