javascript - Passing a the variable to my erb code -


in ruby on rails application have view lists recods.

i have filters on page javascript onclick events on them retrieve ids , filters records on page.

the ids of buttons clicked stored in javascript variable

var selected = []; 

in index.html.erb use value of selected[] array retrieve data database , filter index page.

i saw in other posts cannot pass javascript variables erb code since the latter executed in server.

how pass selected ids erb function using ajax or way?

    <% post.recent(**selected**).each |post| %>        .....     <% end %> 

the way can think of submitting form selected part of params hash, , suppose it.

for example

<input type='hidden' value="selected['cool', 'fun', 'happy', 'ruby']" />

this accessible in controller params[:selected], , there make instance variable in

@selected = params[:selected] 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -