2017-09-09 6 views
-1

内のparamsを定義し、私は結果ページからの検索のparamsを保存したいです変数やフォームフィールドを複製しないように私の連絡先ページの方法でそれらを取得私は結果ページやコンタクトページを持っているか、私のコントローラでは別の方法</p> <p>でそれを使用する変数でのparamsを定義知っているだろう変数

マイ結果ページ

def result 
    if params[:room_type].present? && params[:location].present? && params[:nb_piece].present? 
      @biens = Bien.near(params[:location], 1, units: :km).where(room_type: params[:room_type], nb_piece: params[:nb_piece]) 
    end 
     @users = User.where(id: @biens.reorder(:user_id).pluck(:user_id), payer: true) || User.where(id: @biens.reorder(:user_id).pluck(:user_id), subscribed: true) 
end 

私はこれは私が唯一の電子メールと電話を依頼する必要があります。そのように、私の他の方法ではparamsは保存したいです私の書式

def contact 
    wufoo(params[:location], params[:room_type], params[:nb_piece], params[:email], params[:phone]) 
end 

マイwufoo

def wufoo(adresse, type, pieces, email, phone) 
    require "net/http" 
    require "uri" 
    require "json" 

    base_url = 'https://wako94.wufoo.com/api/v3/' 
    username = 'N5WI-FJ6V-WWCG-STQJ' 
    password = 'footastic' 

    uri = URI.parse(base_url+"forms/m1gs60wo1q24qsh/entries.json") 

    request = Net::HTTP::Post.new(uri.request_uri) 
    request.basic_auth(username, password) 

    request.set_form_data(
     'Field7' => adresse, 
     'Field9' => type, 
     'Field12' => email, 
     'Field11' => phone, 
     'Field8' => pieces 
    ) 

     response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme =='https'){ 
      |http|http.request(request) 
     } 

     puts JSON.pretty_generate(JSON[response.body]) 
end 

答えて

1

これは、ユーザーが連絡する検索からどのようになるに依存します。私は、連絡フォームが検索からリンクされていると仮定し、彼らは最後の検索の情報に関してあなたに連絡したいと思っています。

ここで簡単な方法は、セッション内で最後の検索を保存し、それを参照することです。

def search 
    store_params_in_session 
    # .. your search logic here 
end 

def contact 
    last_search = session[:last_search] 
    if last_search.blank? 
    # .. some error handling if no search is available 
    return 
    end 

    wufoo(last_search[:location], #.. you get the idea 
end 

private 

def store_params_in_session 
    session[:last_search] = { 
    location: params[:location], 
    # .. more params here 
    } 
+0

ご協力いただきありがとうございます。私はあなたのソリューションを試しましたが、私はセッションで自分のパラメータを保存することに成功しませんでした –

関連する問題