· 2 min read

Screencast: Rails für mobile Geräte

Download:

Download (55.4 MB, 13:26) alternative download for iPod & Apple TV (22.4 MB, 13:26)

Resourcen:

Quellcode:

[ruby] # config/initializers/mime_types.rb Mime::Type.register_alias “text/html”, :mobile

# application_controller.rb before_filter :prepare_for_mobile

private

def mobile_device? if session[:mobile_param] session[:mobile_param] == “1” else request.user_agent =~ /Mobile|webOS/ end end helper_method :mobile_device?

def prepare_for_mobile session[:mobile_param] = params[:mobile] if params[:mobile] request.format = :mobile if mobile_device? end [/ruby]

[html] <%= stylesheet_link_tag ‘mobile’ if mobile_device? %> …

<% if mobile_device? %> <%= link_to “Full Site”, :mobile => 0 %> <% else %> <%= link_to “Mobile Site”, :mobile => 1 %> <% end %>

<%= h(yield(:title) || "Untitled") %><%= stylesheet\_link\_tag "/jqtouch/jqtouch.min.css", "/jqtouch/themes/apple/theme.min.css" %> <%= javascript\_include\_tag "/jqtouch/jquery.1.3.2.min.js", "/jqtouch/jqtouch.min.js", "mobile" %> <%= yield(:head) %>
<%- if show\_title? -%>
<%= link\_to "Back", nil, :class => "back" unless current\_page? root\_path %>

<%=h yield(:title) %>

<%= link\_to "Full Site", root\_url(:mobile => 0), :class => "button", :rel => "external" %> <%= yield(:toolbar) %>
<%- end -%> <% unless flash.empty? %>
<%- flash.each do |name, msg| -%> <%= content\_tag :div, msg, :id => "flash\_#{name}" %> <%- end -%>
<% end %> <%= yield %>
<% title "Projects" %>
    <% for project in @projects %>
  • <%= link\_to h(project.name), project %> <%= project.tasks.size %>
  • <% end %>
  • <%= link\_to "New Project", new\_project\_path %>
\[/html\]
Back to Blog