我有一个应用程序,上面有两个用户界面。
第一个适用于普通用户,第二个适用于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中指定。