Rails3 和 Respond_with 问题

发布于 2024-10-11 16:53:12 字数 1045 浏览 4 评论 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 is ... 而不是通过调用 to_format 方法,因为它被指定到 doc

I have an application, on which I have two user interfaces.

The first one is for normal users and the second one is for iphone users.

Everything was working fine until i refactored my code within controller to use the respond_with declarative instead of respond_to.

The application is still working for the html interface(:format => :html) but not on the iphone interface(:format => :iphone).

On the iphone, when I do the following action (:index, :new, :edit, :show) it works.

But when i do (:create, :update, :destroy), I get errors saying the template is not found(create.iphone.haml for example).

On my controller I have

respond_to :html, :iphone

And then for example, the edit and the update action

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

In fact, I would like the :iphone format is handle as :html is ... and not by calling the to_format method as it is specified into the doc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2024-10-18 16:53:12

自己解决了。

只需将其添加到初始值设定项文件中:

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

Solved it by myself.

Just need to add this to an initializer file :

ActionController::Responder.class_eval do
  alias :to_iphone :to_html
end
旧人哭 2024-10-18 16:53:12

如果你这样做怎么办:

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

What if you do:

respond_with(@refund, :location => project_refunds_path(@project)) do |format|
  format.iphone { whatever you had here before refactoring }
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文