2015-06-23 75 views
-1

我試圖將參數(useremail,costprojects)從一個控制器動作傳遞到另一個控制器動作。Rails 3.2將參數從一個控制器動作傳遞到另一個

這裏是控制器代碼:

def pdfemail 
    costprojects = Costproject.find(params[:costproject_ids]) 
    useremail = current_user.email 
    CostprojectsController.delay.pdfemail2(params: { useremail: useremail, costprojects: costprojects }) 
    redirect_to :back 
    flash[:notice] = 'An Email containing a PDF has been sent to you!' 
    end 

    def self.pdfemail2 
    @useremail = params[:useremail] 
    @costprojects = params[:costprojects] 
    ... 

但是,我得到:

wrong number of arguments (1 for 0) 

延遲項目顯示:

object: !ruby/class 'CostprojectsController' 
method_name: :pdfemail2 
args: 
- :params: 
    :useremail: [email protected] 
    :costprojects: 
    - !ruby/ActiveRecord:Costproject 
     attributes: 
     id: 8 
... 

感謝您的幫助!

回答

0

如果你想通過一些PARAMS同時重定向到另一個動作,使用的ActionController ::參數:

def search 
    redirect_to :index, params: { query: params[:q] } 
end 

http://api.rubyonrails.org/classes/ActionController/Base.html

+0

尤里,看到我UPDATE1 - 謝謝。 – Reddirt

+1

不,這些行爲不能像那樣工作,它們不是直接被調用的。如果你需要一些邏輯,發送電子郵件,並且你想在後臺運行它,然後創建一個工作。 –

相關問題