上面的截图是应该出的效果,下面这个不能加入到 layout 正常的写法,
<div data-role="content">
<div id="main" class="clearfix">
<div id="enterRight">
<h2>找回密码</h2>
<%= form_tag '/users/do_forget_pass', :remote => true, :html => {"data-ajax" => false} do -%>
<span class="error_notice"><%= flash[:notice] %></span>
<table class='login_tab'>
<tr>
<td>手机号码:</td>
<td><%=text_field_tag :mobile, nil, :class=>'textBox' %></td>
</tr>
<tr>
<td></td>
<td colspan="2">
<%= submit_tag "找回密码",:id => 'enterBt', :disable_with => "找回密码...." %>
</td>
</tr>
</table>
<% end %>
</div>
</div>
</div>
controller
#coding:utf-8
class SessionsController < ApplicationController
layout "login"
def new
@return_url = params[:return_url]
if request.xhr?
render :file => "/sessions/traveller", :layout => false
else
respond_to do |format|
format.mobile { render :layout => "application", :action => "new" }
end
end
end
def forgetpassword
logger.info("forget_password")
mobile = params[:mobile]
if mobile.present?
user = User.find_by_mobile(mobile)
if user
unless user.role == 'traveller'
receiver = user.mobile
if defined?(Random) # ruby 1.9.3
pass = Random.new.rand(1000..9999)
else
pass = (1000..9999).to_a.choice
end
if user.update_attributes(:password => pass, :password_confirmation => pass)
content = "您申请了密码重置,您的新密码为#{pass},您可以登录后进行密码修改"
SMS.send(receiver, content)
end
flash.now[:notice] = '新密码我们已经发送到您手机'
else
flash[:notice] = '找回密码失败'
end
respond_to do |format|
format.html
format.mobile { render :layout => "application" , :action => "new"}
end
else
flash.now[:notice] = '对不起,该手机号码不存在'
render "forgetpassword"
end
else
flash.now[:notice] = '请输入手机号'
render "forgetpassword"
end
end
application.mobile.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta charset="utf-8">
<title><%= ( @page_title) %></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/assets/jquery.mobile.structure-1.2.0.css"/>
<link rel="stylesheet" href="/assets/mobile/green.css"/>
<link rel="stylesheet" href="/assets/mobile/home_mobile.css"/>
<script src="/assets/jquery.1.8.3.min.js" type="text/javascript"></script>
<script src="/assets/jquery.mobile-1.2.0.min.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page" data-theme="a">
<div data-role="header" data-position="inline">
<h1><%= @page_title) %></h1>
<% if controller_name == 'welcome' && action_name == "home" %>
<a href="#popupMenu" data-icon="gear" class="ui-btn-right" data-rel="popup">帐户</a>
<% else %>
<a href="/" data-rel="back" data-icon="back">后退</a>
<!--<a href="/" data-icon="home" data-direction="reverse" target="_self">首页</a>-->
<% end %>
</div>
<div data-role="popup" id="popupMenu" data-theme="a">
<ul data-role="listview" data-inset="true" style="min-width:210px;" data-theme="b">
<% if current_user.blank? %>
<li><a href='<%= log_in_path %>' target="_self">登录</a></li>
<li><a href="<%= sign_up_path(:role => 'traveller') %>" target="_self">注册</a></li>
<% else %>
<li><a href="<%= traveller_orders_path %>" target="_self">我的订单</a></li>
<li><a href="<%= log_out_path %>" target="_self">退出</a></li>
<% end %>
</ul>
</div>
<div data-role="content">
<%= yield %>
</div>
<!-- /content -->
<div data-role="footer" class="podfoot">
<div class="footer">
<ul style="margin: 0px auto;width: 100%; display:inline;">
<li style=""><a href="/" data-icon="home" data-direction="reverse" target="_self">首页</a></li>
<li><a href="/welcome/about" target="_self">关于我们</a></li>
<li style="border:0;margin:0;padding:0;"><%= link_to "电脑版", url_for(:only_path => false, :overwrite_params => {})+"version=desktop", "data-ajax" => "false" %></li>
</ul>
</div>
</div>
</div>
<!-- /page -->
</body>
</html>