2013-07-17 3 views
0

나는 보석 상자를 사용하여 재활용 응용 프로그램을 작성하고 있습니다. 쓰레기통/재활용 휴지통 위치 등으로지도를 표시하려면 레일즈를 사용하십시오. 이름과 주소가 속성 인 trash.rb 모델. 이 보석을 사용하면 주소 속성을지도의 마커 및 위도/경도로 변환 할 수 있습니다.스핑크스에 게시하지 않음, 양식을 사용하여 양식에 양식을 전달할 수 없음

스핑크스 기능을 구현하려고합니다. 사용자가 '논문'을 재활용하고 싶다고 말하면 내 테이블의 내 카테고리 열 아래에 있습니다. 범주 열의 색인을 생성했습니다. 내 희망은 사용자가 '종이'를 게시 할 때 동일한 카테고리의 주소 만지도에 표시된 마커를 갖게된다는 것입니다.

모든 항목이 올바르게 색인 생성되었습니다. 어떤 오류도 발생하지 않지만 아무 것도 일어나지 않습니다.

현재 인스턴스를 양식에 전달하는 데 문제가 있습니까? 나는이 지난 밤을 생각하고 편집 중입니다. 여기

class TrashesController < ApplicationController 
    # GET /trashes 
    # GET /trashes.json 


    def index 
    @trashes = Trash.search(params[:search]) 
    end 
    end 


    # GET /trashes/1 
    # GET /trashes/1.json 
    def show 
    @trash = Trash.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render json: @trash } 
    end 
    end 

    # GET /trashes/new 
    # GET /trashes/new.json 
    def new 
    @trash = Trash.new 

    respond_to do |format| 
     format.html # new.html.erb 
     format.json { render json: @trash } 
    end 
    end 

    # GET /trashes/1/edit 
    def edit 
    @trash = Trash.find(params[:id]) 
    end 

    # POST /trashes 
    # POST /trashes.json 
    def create 
    @trash = Trash.new(params[:trash]) 

    respond_to do |format| 
     if @trash.save 
     format.html { redirect_to @trash, notice: 'Trash was successfully created.' } 
     format.json { render json: @trash, status: :created, location: @trash } 
     else 
     format.html { render action: "new" } 
     format.json { render json: @trash.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PUT /trashes/1 
    # PUT /trashes/1.json 
    def update 
    @trash = Trash.find(params[:id]) 

    respond_to do |format| 
     if @trash.update_attributes(params[:trash]) 
     format.html { redirect_to @trash, notice: 'Trash was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render action: "edit" } 
     format.json { render json: @trash.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /trashes/1 
    # DELETE /trashes/1.json 
    def destroy 
    @trash = Trash.find(params[:id]) 
    @trash.destroy 

    respond_to do |format| 
     format.html { redirect_to trashes_url } 
     format.json { head :no_content } 
    end 
    end 

trash.rb 모델

class Trash < ActiveRecord::Base 
    attr_accessible :address, :name, :category, 

    acts_as_gmappable 

    def gmaps4rails_address 
    "#{address}" 
    end 

    def gmaps4rails_infowindow 
    "#{self.address}" 
    end 
end 

이 index.html.erb이

<h1>Listing Boston/Cambridge trash bin locations</h1> 
<%= gmaps4rails(@json) %> 
<table> 
    <tr> 
    <th>Name</th> 
    <th>Address</th> 
    <th>Category</th> 
    <th></th> 
    <th></th> 
    </tr> 

<% @trashes.each do |trash| %> 
    <tr> 
    <td><%= trash.name %></td> 
    <td><%= trash.address %></td> 
    <td><%= trash.category %></td> 
    <td><%= link_to 'Edit', edit_trash_path(trash) %></td> 
    <td><%= link_to 'Destroy', trash, method: :delete, data: { confirm: 'Are you sure?' } %></td> 
    </tr> 
<% end %> 
</table> 

<br /> 

<%= link_to 'New Boston Solar Powered Trash Can Location', new_trash_path %> 

<%= form_tag trashes_path, method: :get do %> 
    <div class="field"> 
    <%= text_field_tag :search, params[:search] %> 
    <%= submit_tag "Search", name: nil %> 
    </div> 
<% end %> 

내가 변경 한 단지 인덱스 방법에 초점을 맞추고 내 trashes_controller.rb입니다 스핑크스 기능을 테스트하기위한 나의 index.html.erb.

<%= link_to 'New Boston Solar Powered Trash Can Location', new_trash_path %> 

<%= form_tag trashes_path, method: :get do %> 
    <div class="field"> 
    <%= text_field_tag :search, params[:search] %> 
    <%= submit_tag "Search", name: nil %> 
    </div> 
<% end %> 

레일을 콘솔로 사용하여 모델을 검색 할 수 있습니다. 그러나 아무것도 표시되지 않습니다.

답변

1

보기에서 @trashes 인스턴스 변수를 사용하고 있지만 검색 결과는 @searchtrashes 인스턴스 변수에 있습니다. 표시된 개체에 검색어가 반영되도록하려면 대신 해당 항목을 사용해야합니다.

+0

나를 위해 작동하지 않습니다. 내 인덱스 메소드는 위와 같은 form_tag를 가진 하나의 인스턴스'@trashes = Trash.search (params [: search])'만 갖는다. 폼이 하나만 있기 때문에 폼을 찾을 수 있다고 생각했지만 여전히 검색을 표시하지 않습니다. – Jngai1297

+0

양식을 제출할 때 레일스 로그의 출력은 어떻게됩니까? – pat

+0

2013-07-18 14:21:19 -0400에 127.0.0.1에 '시작됨/휴지통? utf8 = % E2 % 9C % 93 & search = 휴지통 + & 커밋 = 검색' TrashesController # index by HTML로 처리 매개 변수 : 0.83) 레이아웃/애플리케이션 (0.8ms) 내에 휴지통/index.html.erb 렌더링 됨 완료 됨 200 {OK} {OK} {OK}를 클릭합니다. 52ms (보기 : 52.0ms | ActiveRecord : 0.0ms)'이 (가) 올바르게 처리되지만 결과를 표시하지 않습니다. – Jngai1297