יום חמישי, 27 ביוני 2013

Start handle the searching in ROR

The modal

  1: class SearchFor < ActiveRecord::Base
  2:   attr_accessible :pharse
  3: end
  4: 

The controller

  1: class OperatorsController < ApplicationController
  2:   # GET /operators
  3:   # GET /operators.json
  4:   def index
  5:     @operators = Operator.all
  6:     @searchP  = SearchFor.new 
  7:   @searchP.pharse = "zvika"
  8:   
  9:     respond_to do |format|
 10:       format.html # index.html.erb
 11:       format.json { render json: @operators }
 12:     
 13:   end
 14:   end

The view

  1: <h2>Search for operator:</h2>
  2: 
  3:  <div class="field">
  4:     <p>The search pharse: <%= @searchP.pharse%><br /></p>
  5:  </div>
  6: 

The result
http://localhost:3000/operators
Capture41

אין תגובות:

הוסף רשומת תגובה