在 rhoMobile 中单击按钮时显示视图

发布于 2024-12-22 06:18:55 字数 798 浏览 7 评论 0原文

我在 rhomobile 中创建了一个简单的项目。 我的主屏幕显示一个文本框和一个按钮。

这是 index.erb 中的代码

<div data-role="content">
<br /><br />
 Email Address : <input type="text" name="Email" /><br />
  <form method="POST" action="<%= url_for(:action =>:show_VibLoc) %>">
  <input type="submit" value="Submit" />

</form>

现在我在应用程序文件夹下的设置文件夹中创建了一个新文件VibLoc.erb

VibLoc.erb 中,我仅显示两个按钮。

在设置文件夹下的 controller.rb 文件中,我创建了一个函数 show_VibLoc

,此函数呈现 VibLoc.erb 文件

,这里是代码:

def show_VibLoc
render :action => :VibLoc
end

代码编译成功,但是当我单击该按钮时,我看不到我的 VibLoc 视图。

我在这里做错了什么?

I have created a simple project in rhomobile.
My home screen shows a text box and a button.

here is the code for that in index.erb

<div data-role="content">
<br /><br />
 Email Address : <input type="text" name="Email" /><br />
  <form method="POST" action="<%= url_for(:action =>:show_VibLoc) %>">
  <input type="submit" value="Submit" />

</form>

Now I have created a new file VibLoc.erb in settings folder which is under app folder.

in VibLoc.erb i am showing just two buttons.

In the controller.rb file under settings folder i have created a function show_VibLoc

in This function it renders the VibLoc.erb file

here is the code:

def show_VibLoc
render :action => :VibLoc
end

The code compiles successfully but when i click on that button i cant see my VibLoc view.

what i am doing wrong here??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时间海 2024-12-29 06:18:56

最后我自己解决了。

不要在 index.erb 中编写此代码,而是

<div data-role="content">
<br /><br />
Email Address : <input type="text" name="Email" /><br />
<form method="POST" action="<%= url_for(:action =>:show_VibLoc) %>">
<input type="submit" value="Submit" />

</form>

将其替换为此代码

<div data-role="content">
<br /><br />
<div data-role="fieldcontain">
  Email Address : <input type="text" name="Email" /><br />
  </div>
  <form method="POST" action="<%= url_for(:controller => :Settings, :action =>:show_VibLoc) %>">
  <input type="submit" value="Submit" />

</form>

感谢您查看此问题:)

Finally i resolved it by my self.

Instead of writing this code in index.erb

<div data-role="content">
<br /><br />
Email Address : <input type="text" name="Email" /><br />
<form method="POST" action="<%= url_for(:action =>:show_VibLoc) %>">
<input type="submit" value="Submit" />

</form>

replace it with this one

<div data-role="content">
<br /><br />
<div data-role="fieldcontain">
  Email Address : <input type="text" name="Email" /><br />
  </div>
  <form method="POST" action="<%= url_for(:controller => :Settings, :action =>:show_VibLoc) %>">
  <input type="submit" value="Submit" />

</form>

Thanks for looking at this question :)

染年凉城似染瑾 2024-12-29 06:18:55

曾经遇到过同样的问题,我发现的方法是:

  1. 在项目的 public/js 文件夹中创建一个 .js 文件,并使用从控制器调用方法的函数:

    函数 ajaxBridge(方法,funcName,onSuccess)
    {
    $.ajax({
        类型:方法,
        url: 函数名,
        异步:真,
        错误:函数(xhr){alert(“自定义未捕获的AjaxBridge错误11:”+“
    ”+ xhr.responseText);}, 成功:onSuccess }); }
  2. 在您的 .erb 文件或视图上您可以拥有:

    ;
    
  3. 在同一页面上创建一个脚本来调用我们的 ajax 方法,我还将登录信息发送到该方法:

    <脚本类型=“text/javascript”>
    
      函数 doValidation(){
        var 登录 = $('input#login').val();
        var 密码 = $('输入#密码').val();
        ajaxBridge("POST","<%= url_for :controller => :调查, :action => :do_login %>"+"?login="+login +"&password="+password,function (){});
      }
    
    

注意:请包含

指定ajax的来源。

希望我有所帮助。

Had faced the same issue once, the approach i found out was:

  1. to create a .js file in the public/js folder in the project with a function to call a method from the controller :

    function ajaxBridge(method,funcName,onSuccess)
    {
    $.ajax({
        type: method,
        url: funcName,
        async: true,
        error: function(xhr){alert("Custom Uncaught AjaxBridge Error 11 :" + "<br/>" + xhr.responseText);},
        success: onSuccess
        });
    }
    
  2. on you .erb file or view you can have :

    <input type="button" value="Login" onclick="doValidation()"/>
    
  3. create a script on the same page to call our ajax method, i am also sending login information to the method :

    <script type="text/javascript">
    
      function doValidation(){
        var login = $('input#login').val();
        var password = $('input#password').val();
        ajaxBridge("POST","<%= url_for :controller => :Survey, :action => :do_login %>"+"?login="+login +"&password="+password,function(){});
      }
    </script>
    

Note: Do include
<script type="text/javascript" src="/public/js/AjaxConnector.js"></script>
to specify the source for the ajax.

hope i helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文