2011-01-13 41 views
0

我有一個應用程序,我有兩個用戶界面。Rails3和Respond_with問題

第一個用於普通用戶,第二個用於iphone用戶。

一切工作正常,直到我重構我的代碼內控制器使用respond_with聲明而不是respond_to。

該應用程序仍然爲html界面(:format =>:html)工作,但不在iphone界面上(:format =>:iphone)。

在iphone上,當我執行以下操作(:index,:new,:edit,:show)時,它可以工作。

但是,當我做(:創建,:更新,:銷燬),我得到錯誤,說模板沒有找到(例如create.iphone.haml)。

在我的控制器我有

respond_to :html, :iphone 

再例如,編輯和更新操作

def edit 
    @refund = Refund.find(params[:id]) 
    respond_with(@refund) 
    end 
    def update 
    @refund = Refund.find(params[:id]) 
    if @refund.update_attributes(params[:refund]) 
     flash[:notice] = 'Refund was successfully updated.' 
    end 
    respond_with(@refund, :location => project_refunds_path(@project)) 
    end 

其實,我想:iphone格式如下處理:HTML是...而不是通過調用doc中指定的to_format方法。

回答

1

由我自己解決它。

只是需要把它添加到一個初始化文件:

ActionController::Responder.class_eval do 
    alias :to_iphone :to_html 
end 
0

,如果你做什麼:

respond_with(@refund, :location => project_refunds_path(@project)) do |format| 
    format.iphone { whatever you had here before refactoring } 
end 
+0

是的,這可能是一個解決方案。但對我來說這還不夠。 Iphone和html格式與他們應該回應的方式相同。如果可能,我正在尋找更好的方法。 Thx無論如何;) – Arkan 2011-01-14 02:54:01