Rails3 和 Respond_with 问题
我有一个应用程序,上面有两个用户界面。
第一个适用于普通用户,第二个适用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自己解决了。
只需将其添加到初始值设定项文件中:
Solved it by myself.
Just need to add this to an initializer file :
如果你这样做怎么办:
What if you do: