0

我有一个应用程序,上面有两个用户界面。

第一个适用于普通用户,第二个适用于iphone用户。

一切正常,直到我在控制器中重构我的代码以使用respond_with声明而不是respond_to。

该应用程序仍然适用于 html 界面(:format => :html),但不适用于 iphone 界面(:format => :iphone)。

在 iphone 上,当我执行以下操作(:index、:new、:edit、:show)时,它可以工作。

但是当我这样做时(:create,:update,:destroy),我收到错误说找不到模板(例如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 是......而不是通过调用 to_format 方法,因为它在doc中指定。

4

2 回答 2

1

自己解决了。

只需将其添加到初始化文件中:

ActionController::Responder.class_eval do
  alias :to_iphone :to_html
end
于 2011-01-21T03:52:54.700 回答
0

What if you do:

respond_with(@refund, :location => project_refunds_path(@project)) do |format|
  format.iphone { whatever you had here before refactoring }
end
于 2011-01-13T18:15:31.500 回答