I am trying to use open method of open-uri gem in Rails.
When I try it in standalone Ruby application I just require it on top of the file and everything is ok. But now I want it to use it controller in Rails app. Is it advisable to put require on top of controller?
Controller code:
def search
if params.has_key? :q
params[:q] =~ /\?v=(.*?)&/
xmlfeed = Nokogiri::XML(open("http://gdata.youtube.com/feeds/api/videos?q=#{$1}"))
if xmlfeed.at_xpath("//openSearch:totalResults").content.to_i == 1
flash[:notification] = "Video #{xmlfeed} found"
#save video id to database
redirect_to root_url
else
flash[:error] = "Video #{xmlfeed} not found"
redirect_to root_url
end
else
flash[:error] = "You didn't insert video URL."
redirect_to root_url
end
end
Error:
No such file or directory - http://gdata.youtube.com/feeds/api/videos?q=cSnkWzZ7ZAA