this is what I have:
<a href="#" onclick="image_viewer_on(<%= e.id %>, <%= params[:controller] %>); return false;">
but I get a 'my_controller_name' is undefined error?
edit
I tried:
<a href="#" onclick="image_viewer_on(<%= e.id %>, <%= controller_name %>); return false;">
<a href="#" onclick="image_viewer_on(<%= e.id %>, '<%= controller_name %>', 'index'); return false;">
with the same result, and
<a href="#" onclick="image_viewer_on(<%= e.id %>, <%= controller_name.to_i %>); return false;">
which works. Can I parse it somehow, or what do you think?
ok so this is how I fixed it , I added some quotes around the <%= controller_name %>
<a href="#" onclick="image_viewer_on(<%= e.id %>, '<%= controller_name %>', 'index'); return false;">
You ca see here a discussion about getting the controller name in the view: http://www.ruby-forum.com/topic/140912
params[:controller]
or
controller.controller_name
You did not specify if yyour error occurs in javascript or ruby. My guess is that is in javascript and it is caused by the fact that you did not enclosed by quotes the controller name and javascript thinks it is a variable with that name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.