将参数从视图传递到控制器

问题描述 投票:0回答:1

我有我的Rails应用程序的登录表单视图。

登录表单代码-

<h1>Log In</h1>
<%= form_tag dashboard_path do %>
  <div class="field">
    <%= label_tag :phone %><br>
    <%= text_field_tag :phone %>
  </div>
  <div class="field">
    <%= label_tag :password %><br>
    <%= password_field_tag :password %>
  </div>
  <% end %>
  <%= form tag sign_in_path do %>
  <div class="actions">
    <%= submit_tag "Log In"%>
  </div>
<% end %>

所以我在这里尝试的是使用phonepassword作为我在登录页面中输入的参数,将提交按钮重定向到controller#action(sign_in_path)。

此登录代码被复制,因为我对HTML / Angular的了解为零,而且我在其余视图中使用jbuilder而不是ERB。

UPDATE-在第一个stdout请求之后的GET

Started GET "/dashboard" for 127.0.0.1 at 2019-11-27 11:29:49 +0530 Processing by HulksController#new as HTML Rendering hulks/new.html.erb Rendered hulks/new.html.erb (Duration: 1.0ms | Allocations: 590) Completed 200 OK in 2ms (Views: 1.9ms | ActiveRecord: 0.0ms | Allocations: 1172)

在第二次stdout请求之后,按下登录按钮后,[post

Started POST "/sign_in" for 127.0.0.1 at 2019-11-27 11:30:03 +0530 Processing by HulksController#create as HTML Parameters: {"commit"=>"Log In"} App 11639 output: {"commit"=>"Log In", "controller"=>"hulks", "action"=>"create"} App 11639 output: Completed 200 OK in 4ms (Views: 0.2ms | ActiveRecord: 0.6ms | Allocations: 1273)

ruby-on-rails ruby view
1个回答
-1
投票
 <h1>Log In</h1>
 <%= form_tag sign_in_path do %>
 <div class="field">
   <%= label_tag :phone %><br>
   <%= text_field_tag :phone %>
 </div>
<div class="field">
  <%= label_tag :password %><br>
  <%= password_field_tag :password %>
</div>
<div class="actions">
 <%= submit_tag "Log In"%>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.