0

I'm trying to work out where I should put the following snippets of code in my Rails 4 app in order for them to be included in the asset pipeline.

The following is used on my form:

<input id="tag" type="text" name="tags" value="">

<p>
<a class="tag">aaa</a><br/>
<a class="tag">bbb</a><br/>
<a class="tag">ccc</a><br/>
<a class="tag">ddd</a><br/>
<a class="tag">eee</a>
</p>

Where should the following code be placed so that is is triggered by the above html?:

$('a.tag').live('click', function(e){
$('#tag').val(this.innerHTML);
return false; 
});

Here is working example http://jsfiddle.net/Kaf3V/4/

UPDATE: The JS, is being loaded correctly, but simply doesn't work in Rails 4(?)

Thanks

3
  • I maybe be off topic but, you really need to switch to link.on() at some point. The syntax is $('#aParentElement').on('click', '#targetElement', function(e){. Just a thought. EDIT, linklive have been removed from the new versions of jquery, so any update the jquery script would brake the script. Commented Dec 16, 2013 at 20:36
  • ^^ Added to my To Do list Commented Dec 16, 2013 at 20:39
  • i did some blogs posts (long ago) on javascript and rails asset pipeline that might be worth taking a look at: jessehouse.com/blog/2011/05/29/rails-31-javascript-execution AND jessehouse.com/blog/2011/05/26/rails-31-asset-pipeline Commented Dec 16, 2013 at 20:46

1 Answer 1

1

Put them in app/assets/javascripts/some_file.js

If you haven't modified your app/assets/javascripts/application.js file, rails should pick it up next time you start your server.

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

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.