2012-09-26 46 views
0

我試圖從一個站點傳遞參數到下一個站點,並使用它,但我有一個問題!傳遞參數與ror

店>指數

<h1>All Priorities</h1> 


<% @buildings.each do |building| %> 
<div class="entry"> 
    <div class="img"> 
    <%= image_tag (building.photo.url)%></div> 
    <div class=" disc"> 
    <h3>Name of the Bulding: <%= building.title %></h3> 
    <h4>Status: <%= building.status %></h4> 
    Info: <%=sanitize(building.description)%> 
    <div class="price_line"> 
     <span class="price">Price: <%= sprintf("€ %0.02f",building.price)%></span><br/> 
     <div class="button"> 
     <%= button_to "I Want to See it", new_seeit_path(building.id), :method => :get%> 

</div> 
    </div> 
    </div> 


    <%end%> 
    <div class="pages"> 
    <%= will_paginate @buildings %></p> 
    </div> 

在接下來的網站時,我按下按鈕,我想看到它,它說:

http://localhost:3000/seeits/new.4? 

,如果不打開網頁

我刪除(building.id)它說:

http://localhost:3000/seeits/new? 

需要我到下一個站點,但沒有PARAM

意見> wish_receive.text.erb < =這給我的信息在電子郵件

You got a wish from <%= @seeit.name %> 
<%= @seeit.telephone_number %> 
<%= @seeit.email %> 
<%= @seeit.comments %> 

路線

Projectproperties::Application.routes.draw do 
    resources :seeits 

    get "about/index" 

    get "contact/index" 

    get "store/index" 

    resources :buildings 
root :to => 'store#index', :as => 'store' 
end 

seeits_controller

def new 
    @seeit = Seeit.new 

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

    # GET /seeits/1/edit 
    def edit 
    @seeit = Seeit.find(params[:id]) 
    end 

    # POST /seeits 
    # POST /seeits.json 
    def create 
    @seeit = Seeit.new(params[:seeit]) 

    respond_to do |format| 
     if @seeit.save 
     Notifier.wish_received(@seeit).deliver 
     format.html { redirect_to(store_url, notice: 'Thank you for your wish will contac you very soon.') } 
     format.json { render json: @seeit, status: :created, location: @seeit } 
     else 
     format.html { render action: "new" } 
     format.json { render json: @seeit.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

耙路航命令

 seeits GET /seeits(.:format)    seeits#index 
       POST /seeits(.:format)    seeits#create 
    new_seeit GET /seeits/new(.:format)   seeits#new 
    edit_seeit GET /seeits/:id/edit(.:format) seeits#edit 
     seeit GET /seeits/:id(.:format)   seeits#show 
       PUT /seeits/:id(.:format)   seeits#update 
       DELETE /seeits/:id(.:format)   seeits#destroy 
    about_index GET /about/index(.:format)  about#index 
contact_index GET /contact/index(.:format)  contact#index 
    store_index GET /store/index(.:format)  store#index 
    buildings GET /buildings(.:format)   buildings#index 
       POST /buildings(.:format)   buildings#create 
new_building GET /buildings/new(.:format)  buildings#new 
edit_building GET /buildings/:id/edit(.:format) buildings#edit 
    building GET /buildings/:id(.:format)  buildings#show 
       PUT /buildings/:id(.:format)  buildings#update 
       DELETE /buildings/:id(.:format)  buildings#destroy 
     store  /       store#index 
+0

您能否澄清確切的問題是什麼? –

回答

2

你能告訴我們你的routes.rb文件和什麼rake路由輸出嗎?


這裏我們開始吧。

在你的routes.rb文件,補充一點:

resources :seeits do 
    member do 
     post 'new' 
    end 
    end 

在你seeits_controller.rb文件,你的新方法應該是這樣的:

def new 
     # raise params.inspect 
     @seeit = Seeit.new 
     @building = Building.find(params[:building_id]) 

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

最後,在你的視圖文件,與現在,你的按鈕在傳遞變量building_id因爲這

<%= button_to("I want to see it", {:controller => "seeits", :action => "new", :building_id => building.id})%> 

注意更換你button_to代碼一個參數,允許您訪問@building對象。控制器中的新動作現在是一個後置函數,因爲我們正在向服務器發送信息。現在,您可以在新模板中使用@building。希望這可以幫助。

+0

這一個routes.rb? – marios

+0

是的,那routes.rb文件。此外,在您的終端中,輸入「rake routes」併發布您的輸出。對於你的new_seeits_path,這是你的建築控制器中的一個動作嗎? – styliii

+0

seeits是發送電子郵件。我想要的就是讓建築物的標題發送郵件 – marios