Single view template for multiple query formats

I am involved in creating an HTML5 application, and we have created our own MIME type (mobile) for iPhone, Android, etc. So, for example, we have index.html.haml and index.mobile.haml. In many cases, the output will be the same - so my question is: how can I create a presentation file that is used by both request formats for mobile devices and html? And in cases where the view is different, select the correct html or mobile view?

I dig and cannot find a clean and elegant solution.

+3
source share
1 answer

You can process both regular and mobile requests in one block respond_toand explicitly set the template for use. For instance:

respond_to do |format|
  format.any(:html, :mobile)
    render :template => "action.html.erb"
  end
end

, , "" . : : .

+5

Source: https://habr.com/ru/post/1790407/


All Articles