重构 新增加的页面,forget_password.mobile.erb,为什么不能把样式加入,其它的页面就没有问题

fayake · March 05, 2014 · Last by fayake replied at March 05, 2014 · 8029 hits

上面的截图是应该出的效果,下面这个不能加入到 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>

layout 有误?

#1 楼 @Martin91 原来的页面都没有问题就是这个新加的页面不能加入到 layout

直接把其它正常加载的页面复制过来也不行,不知道是什么地方有问题

controller 是不是设置了 layout

forget_password.mobile.erb 你确定这样的命名可以使 layout 使用吗?

#2 楼 @fayake 贴一下 controller 的代码?

#5 楼 @floger 我先换个名这试试

#5 楼 @floger 改名了不行

#6 楼 @Martin91 controller 贴出来了

#4 楼 @kikyous 是有设置您给说下这个设置这个有什么用,我去除了就可以了

@fayake 你的 SessionsController 定义了 layout :login 的方式,你又在 new 里面使用 application layout 你看看是不是这里有问题?

#11 楼 @floger 把 SessionsController 中的 layout "login"删除就可以了,基础不扎实,问题都不知道出哪里,感谢帮忙解决

You need to Sign in before reply, if you don't have an account, please Sign up first.