Collection_select Selected value

Hello,

I’m trying to use collection select to implement filtering for my page.
The
idea is there are a bunch of posts and I want to implement record
filtering
for those.

The first collection box would have parameters like “Date”, “Amount”,
“Category” and based on the selection of this a secondary drop down
would
appear and allow the user to make a selection. The records on this page
would be then filtered based on both the selection.

I have been trying out many things and have googled a lot on collection
but
I have reached a dead end now. I’m pretty new and just started learning
ROR.

You help is much appreciated here.

Thanks in advance.

Note: the code below might be wrong and as of now its not even
compiling…
currently it complaints of “remote_function” not defined…

I have a page that looks like this,

<% if @user.spendings.any? %>

    <h3> Spendings (<%= @user.spendings.count  %>)</h3>



    <%= collection_select(:category, :category, Category.all, :id, 

:name
,

   {:prompt => 'Select'})%>



<%= collection_select :event, :filterType, Filters.all, :id, 

:filterType,
{},

  {

  :onchange => remote_function(

    :url => {:action => "updatelevel", :controller => "Spendings", 

:id =>
1},

    :with => "'level_id='+this.value"

  )}

%>

    <ol class="spendings">

      <%= render @spendings %>

    </ol>

    <%= will_paginate @spendings %>

<% end %>

On Wednesday, January 8, 2014 10:18:33 PM UTC, Himanshu Vikram Tantia
wrote:

would be then filtered based on both the selection.
currently it complaints of “remote_function” not defined…

remote_function was removed in rails 3.1 (it is still available as part
of
the prototype-rails (https://github.com/rails/prototype-rails) gem
In general people are moving away from explicit onchange functions.
Instead
(using jquery) you’d do somthing like

$(’#a_select_box’).on(‘change’, function(){
//this javascript is called when the drop down with id a_select_box is
changed
})

Fred

On Jan 9, 2014, at 8:21 AM, Frederick C. wrote:

In general people are moving away from explicit onchange functions. Instead
(using jquery) you’d do somthing like

$(’#a_select_box’).on(‘change’, function(){
//this javascript is called when the drop down with id a_select_box is changed
})

Hear, hear! The primary advantage to this sort of construction is that
you end up with fewer declared JavaScript functions in the global scope.
This has tremendous benefits to page load speed and in-page performance,
particularly on tiny devices with limited RAM.

Prototype offers this sort of construction as well, and if you use the
prototype_rails gem, you’ll see that all of the helpers that make delete
buttons work, and data-confirm attributes possible, all work there in
exactly the same way, with no inline scripts littering the page.

document.on(‘change’, ‘select.chained’, function(evt, elm){
// do something with elm here whenever it changes
// since this example is a class-based selector, you apply the
// same behavior to all select tags that have the chained classname
});

Walter

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs