Rails: saving value selected in collection_select in the view -


i'm rails newby, , spent of today trying find answer problem, couldn't figure out. think common problem lot of people may looking straightforward answer, here goes:

all want use collection_select statement, store selected value in variable @bno, , use same variable filter out properties belong building.

here's code:

<%= collection_select :property, :buildingnumber, building.all, :streetno, :streetno, {prompt: "building number"},{:class => "form-control"}%>  

as understand looking around so, params[:property][:buildingnumber] should hold selection.

now further down, have code:

<% @properties.filter_by_building(buildingnumber: property.find(params[:property][:buildingnumber])).each |property| %>              <div class="col-sm-6 col-md-4">               <div class="thumbnail relative">                 <%= image_tag property.avatar.url(:medium) %>                 <div class="caption fixedtextheight">                   <h4>building no: <%= property.buildingnumber%></h4><h4>property no: <%= property.number%></h4>                    <p><h5>rented: <%=property.rented%></h5></p>                   <p>                     <a type="button" class="btn btn-default navbar-btn" href=<%= edit_property_path(property) %>>edit</a> <%= link_to "delete", property, method: :delete, :class=>"btn btn-default navbar-btn", data: { confirm: "deleting property delete tenants, expenses, , leases associated it."} %>                      </p>                    </div>               </div>              </div>            <%end%> 

here error get:

nomethoderror in properties#index showing /users//desktop/jr buildings/jrbuilding/app/views/properties/index.html.erb line #31 raised:

undefined method `[]' nil:nilclass extracted source (around line #31):

                 <% @properties.filter_by_building(buildingnumber: property.find(params[:property][:buildingnumber])).each |property| %> 

i'm confused how should save local variables in views, i'm coming java/obj c background, , want simple, filter page based on value user selects in collection_select. need figure out how update page somehow.

anyway helpful tips appreciated, thank in advance!

also want show filter_by_building code in property model:

def self.filter_by_building(opts={})     buildingno = opts[:buildingnumber]     building = building.arel_table      self.where(:buildingnumber => buildingno) end 

thanks much!


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -