I went back and forth after a few messages, and also checked for Railscast detection for mobile devices (# 199). I have a rails3 application that uses jquery and ajax and format.js and it works fine. Now I am trying to extend the application to mobile devices.
I use jquery mobile and everything works fine, but when I use remote => true switch on link_to, it does not treat the request as JS (which usually does in the desktop version).
Here is the link code:
<%= link_to 'Up', '/posts/' + String(rbpost.id) + '/upvote', :remote => true, :class => 'upvote', "data-role" => "button", "data-icon" => "arrow-u", "data-iconpos" => "notext" %>
It is processed as HTML
Started GET "/posts/3/upvote" for 127.0.0.1 at 2012-02-08 11:37:59 -0500 Processing by PostsController
.,. and complains that there is no template:
ActionView::MissingTemplate (Missing template posts/upvote, application/ upvote with {:handlers=>[:erb, :builder, :coffee], :formats=>[:mobile], :locale= [:en, :en]}. Searched in: * "C:/rubydemo/testapp/app/views" ): app/controllers/posts_controller.rb:74:in `upvote'
Here's how things are encoded:
application_controller.rb:
class ApplicationController < ActionController::Base protect_from_forgery before_filter :adjust_format_for_mobile private
mime_types.rb:
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register_alias "text/html", :mobile Mime::Type.register_alias "text/javascript", :mobilejs
posts_controller.rb:
def upvote @post = Post.find(params[:id]) @post.upvote @post.save respond_to do |format| format.js format.mobilejs format.html { redirect_to @post } format.json { render json: @post } end end
I have upvote.js.erb and upvote.mobilejs.erb in my views / posts directory. It registers: a mobile type, but for some reason does not do javascript when it needs it. Any ideas?
thanks