获取弹出框控制值到控制器页面

时间:2014-04-01 05:59:56

标签: jquery ruby-on-rails ajax

我有一个ajax弹出框,我正在使用3 text_field current_passwordnew_passwordre-enter password,但当我点击Submit按钮时,我没有弹出框将值控制为一个 控制器页面,下面是打开弹出框的按钮:

<table align="center" width="73%">
                <tr>
                    <td style="text-align:right;">
                        <div class="button">
                            <a id="ResetPass" class="buttonSearch">Reset</a>
                        </div>
                    </td>
                </tr>
</table>

以下是用于打开弹出框的javascript代码:

<script type="text/javascript">
                var el=document.getElementById("ResetPass");
                el.onclick = show_dialog2;
                function show_dialog2() {
                $( "#dialog" ).dialog();

                }
</script>

以下是弹出框div:

<div id="dialog" title="Reset Password" type="hidden">
                <%= form_tag({ controller: "settings", action: "reset_password"}, remote: "true" ) do |f| %>
                    <table style="text-align:center; vertical-align:top;">
                        <tr>
                            <td>
                                <div>
                                    <%= label_tag(:currentpassword, "Current Password") %>
                                    <%= password_field :tf_currentpassword, :placeholder => "Current Password" %>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div>
                                    <%= label_tag(:newpassword, "New Password") %>
                                    <%= password_field :tf_newpassword, :placeholder => "New Password" %>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div>
                                    <%= label_tag(:re_enterpassword, "Re-enter Password") %>
                                    <%= password_field :tf_re_enterpassword, :placeholder => "Re=enter Password"  %>
                                </div>
                            </td>
                        </tr> 
                    </table>
                    <table align="center" width="63%">
                        <tr>
                            <td style="text-align:right;">
                                <%= submit_tag 'Submit', :id => "_button" %>
                            </td>
                        </tr>
                    </table>
                <% end %>
</div>

以下是用于提交弹出窗体的javascript:

<script type="text/javascript">
$(document).ready(function() {
    // '_button' is the Id of your submit button
    $("#_button").click(function() {            
      $(this).closest("form").submit();
      $("#dialog").dialog("close");
    });
});
</script>

我收到以下错误:

ActionController::InvalidAuthenticityToken

要解决此问题,请添加authenticity_token: "true",如下所示:

<%= form_tag({ controller: "settings", action: "reset_password", authenticity_token: "true"}, remote: "true" ) do |f| %> <% end %>

然后我又收到了另一个错误:

Missing template settings/reset_password, application/reset_password with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "C:/Sites/MentorMentored1/app/views"

以下是控制器页面,我想获得弹出控件值:

def reset_password
    @cp = params[:tf_currentpassword]
    @np = params[:tf_newpassword]
    @rp = params[:tf_re_enterpassword]    
  end

请帮我等你的回复。 感谢。

1 个答案:

答案 0 :(得分:0)

以上错误与视图有关,与控制器无关。您的reset_password操作没有视图。并检查控制器中的参数使用logger调试params散列 e.g。

def reset_password
    Rails.logger.info "\n\n\n******#{params.inspect}******\n\n\n"
end

并检查日志文件中的参数(log / development.log以获取开发环境)。我猜你是在控制器中获取参数。 您可以在page

上查看如何调试rails应用