开发者

Rails3 and Respond_with problem

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(@pro开发者_开发问答ject))
  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.


Solved it by myself.

Just need to add this to an initializer file :

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


What if you do:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜