Showing a View on a button click in rhoMobile

时光毁灭记忆、已成空白 提交于 2020-01-15 11:10:50

问题


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??


回答1:


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.




回答2:


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 :)



来源:https://stackoverflow.com/questions/8603614/showing-a-view-on-a-button-click-in-rhomobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!