1

I have a rails controller for recipes. I have added some additional variable called @recID. I am able to access this variable successfully in index.json.jbuilder.

I can't figure out how to access it in my app.js (which is angular controller file).

My research has covered:

and many other google searches.

Here is a code snippet in from app.js:

$scope.search = function(keywords) {
  return $location.path("/").search('keywords', keywords);
};
// query = $resource('/', {query: "query"});
// query =  $resource('/recipes/:recipeId', {

query =  $resource('/', {
  query: "@recID",
  format: 'json'
});
console.log ("About to write to log query=" + query);
// alert ("query =<" + query + ">");
Recipe = $resource('/recipes/:recipeId', {
  recipeId: "@id",
  format: 'json'
});

2 Answers 2

2

try using gon.gon is a gemused to pass data to js.first you need to install gon.then in your controller you can specify

gon.variable_name = variable_value

in your js

gon.variable_name

https://github.com/gazay/gon https://gist.github.com/shicholas/5937417

Sign up to request clarification or add additional context in comments.

Comments

0

You can set some hidden_field in the HTML with controller variable value and fetch this value in app.js using DOM selector.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.