I added a configuration variable in application.rb such as
module Www
class Application < Rails::Application
...
config.myurl = "http://localhost:8443/play"
end
After something is clicked on my page I would like to use the value of this config var in order to come up with my full url such as mypage.js having
function ClickedOnSomething(someid){
var fullUrl = <value of config.myurl> + '?id='+someid+'.html';
...
}
so that if for example the id of what I clicked on was 1776 then the fullUrl would be the string
http://localhost:8443/play?id=1776.html
I am using Ruby on Rails 3.2.3 and Ruby 1.9.3
One thing I tried was going through the controller like the following:
In application_controller.rb I added
def before_filter
# This variable will be available in all controller actions and views
@url_global = Www::Application.config.myurl
end
In application.html.erb I added
<script type="text/javascript">
var url_global = "<%= @url_global %>"
</script>
Then in mypage.js I did
function ClickedOnSomething(someid){
var fullUrl = @url_global + '?id='+someid+'.html';
...
}
but @url_global is not recognized. I have actually tried many different variations of using the var in javascript but nothing is working for me.