SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2008
    Location
    Jerusalem
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search - I need feedback

    I have created a Search for assets in my real estate app
    and I whant to get a second opinion
    It is working very good but mybe there is a beter way to do this

    This is the view
    Code:
    <div id="search">
    		<% form_for :asset, :url => { :action => :search } do |form| %>
    			<div id="ref1"><label for="asset_settelment_id">ישוב</label><br />
    				<%= collection_select( :id, :name, Settelment.find(:all, :order => "name" ), :id, :name, options ={:prompt => "הכל"}) %>
    			</div>
    			<div id="ref2"><label for=pr_from>מחיר מ ...</label> <br />
                        <select name="pr_from" id="pr_from">
    						<option value="0">הכל</option>
    						<option value="300000">₪300,000</option>
    						<option value="350000">350,000</option>
    						<option value="400000">400,000</option>
    						<option value="450000">450,000</option>
    						<option value="500000">500,000</option>
    						<option value="1000000">1,000,000</option>
    						<option value="2000000">2,000,000</option>
    						<option value="3000000">3,000,000</option>
    						<option value="5000000">5,000,000</option>
    					</select>
    			</div>
    			<div id="ref3"><label  for=pr_to>עד ...</label> <br />
                         <select name="pr_to" id="pr_to">
    						<option value="99000000">הכל</option>
    						<option value="300000">₪300,000</option>
    						<option value="350000">350,000</option>
    						<option value="400000">400,000</option>
    						<option value="450000">450,000</option>
    						<option value="500000">500,000</option>
    						<option value="1000000">1,000,000</option>
    						<option value="2000000">2,000,000</option>
    						<option value="3000000">3,000,000</option>
    						<option value="5000000">5,000,000</option>
    						<option value="99000000">5,000,000 +</option>
    					</select>
    			</div>
    			<div id="ref4"><input id="search-button" type="submit" value="חפש נכסים" name="search"> 
    			</div>
    		<% end %>
    	</div>
    And this is the search method in the asset controller

    Code:
    def search
    		@sid = params[:id] [:name]
    		@pfrom = params[:pr_from]
    		@pto = params[:pr_to]
    		if @sid != '' 
    			@assets = Asset.find(:all, :conditions => ["settelment_id =? and price_shekel >?  and price_shekel <?"  , @sid ,  @pfrom, @pto ])
    		else
    			@assets = Asset.find(:all, :conditions => [" price_shekel >?  and price_shekel <?"  ,  @pfrom, @pto ])
    		end
    		render :action => 'list'
    	end
    Thanks

    Erez

  2. #2
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I were to recommend anything, it would be to move this code into a method on the model:

    Code:
    		if @sid != '' 
    			@assets = Asset.find(:all, :conditions => ["settelment_id =? and price_shekel >?  and price_shekel <?"  , @sid ,  @pfrom, @pto ])
    		else
    			@assets = Asset.find(:all, :conditions => [" price_shekel >?  and price_shekel <?"  ,  @pfrom, @pto ])
    		end
    There are some things you shouldn't try to code at home.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •