· 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 %>
<%- if show\_title? -%>
<% title "Projects" %> <%- end -%> <% unless flash.empty? %><%- flash.each do |name, msg| -%> <%= content\_tag :div, msg, :id => "flash\_#{name}" %> <%- end -%>
<% end %> <%= yield %>- <% for project in @projects %>
- <%= link\_to h(project.name), project %> <%= project.tasks.size %> <% end %>
- <%= link\_to "New Project", new\_project\_path %>