I am working in an interface, that needs information from a video model I created. That means I will need to execute a MySQL query, to get information I need. My code is this, in my interface.js.erb file:
...
function play_vid()
{
low_fps = '<%= @video.low_fps %>' ;
alert(low_fps); //checking
if(low_vid.paused){
low_vid.play();
play_icon.classList.remove("icon-play-circle");
play_icon.classList.add("icon-pause");
}else{
low_vid.pause();
play_icon.classList.remove("icon-pause");
play_icon.classList.add("icon-play-circle");
}
}
...
The above code returns me this:
NoMethodError in Videos#show
Showing /home/user/My Projects/Ruby Projects/Video_APP/app/views/layouts/application.html.erb where line #8 raised:
undefined method `low_fps' for nil:NilClass
(in /home/user/My Projects/Ruby Projects/Video_APP/app/assets/javascripts/jQuery/interface.js.erb)
Extracted source (around line #8):
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "jQuery/jquery-1.7.2.min.js" %>
7: <%= javascript_include_tag "jQuery/jquery-ui-1.8.21.custom.min.js" %>
8: <%= javascript_include_tag "application.js" %>
9: <%= javascript_include_tag "bootstrap-dropdown.js" %>
10: <%= javascript_include_tag "jQuery/interface.js.erb" %>
11: <%= javascript_include_tag "jQuery/events_controls.js" %>
should I use a normal *.js file? what are the main differences and how do I fix my problem?
EDIT:
# GET /videos/1
# GET /videos/1.json
def show
@video = Video.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @video }
end
end
@videovariable is not set aslow_fpsin an undefined method. Did you check whether you actually defined@videoin your controller?interface.js.erbfile is being rendered when it throws the error.@videois not defined. It also might be possible that your controller was not able to find the video because it does not exist and the controller does not check this properly. If you still need more help, post (relevant parts of) the controller code (like the show method).