【发布时间】:2017-09-14 17:03:49
【问题描述】:
我有一个登录页面和一个注册页面。我希望在点击登录或注册按钮后,用户被重定向到另一个视图,这将是一个微博。
注册页面的代码如下。 (如表格部分) -
<h2 class="text-center">Sign Up</h2>
<%= form_for(input_output_SignUp_url) do |f| %>
<%= f.label :first_name,"First name:" %>
<%= f.text_field :first_name %>
<%= f.label :last_name,"Last name:" %>
<%=f.text_field :last_name %>
<%= f.label :email,"Email:" %>
<%= f.email_field :email %>
<%= f.label :phone,"Phone no:"%>
<%= f.text_field :phone %>
<%= f.label :city,"City:" %>
<%= f.text_field :city %>
<%= f.label :addr_1,"Address 1:" %>
<%=f.text_field :addr_1 %>
<%= f.label :addr_2,"Address 2:" %>
<%= f.text_field :addr_2 %>
<%= f.label :state,"State:"%>
<%= f.text_field :state %>
<%= f.label :postal_code,"Postal Code:"%>
<%= f.text_field :postal_code %>
<%= f.label :password,"Password:"%>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation:" %>
<%= f.password_field :password_confirmation, class: 'form-control' %>
<%= button_to "View profile", input_output_micropost_path%>
<% end %>
现在这不起作用。当我点击按钮时,它显示一个错误 - No route matches [POST] "/input_output/SignUp"
路由文件如下:-
root 'static_pages#home'
get 'static_pages/home'
get 'static_pages/genre'
get 'static_pages/accessories'
get 'static_pages/contactus'
get 'static_pages/aboutus'
get 'input_output/Login'
get 'input_output/SignUp'
get 'input_output/micropost'
get '/genre', to: 'static_pages#genre'
get '/accessories', to: 'static_pages#accessories'
get '/aboutus', to: 'static_pages#aboutus'
get 'contactus', to: 'static_pages#contactus'
get 'Home', to: 'static_pages#home'
get '/Login', to: 'input_output#Login'
get '/micropost', to: 'input_output#micropost'
get '/SignUp', to: 'input_output#SignUp'
end
我怎样才能让这个错误消失?
编辑:- 如所问,这是 rake routes 的结果 /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51:警告:常量 ::Fixnum 已弃用
/home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52:警告:常量:: Bignum 已弃用
/home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138:警告: 常量 ::Fixnum 已弃用
rake 中止!
ArgumentError: Missing :controller key on routes definition,请检查您的路由。
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/config/routes.rb:25:in `block in'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/config/routes.rb:1:in `'
/home/gauri/Academics/CS/Ruby on Rails/ScholarShip/ScholarShip/config/environment.rb:5:in `'
任务:TOP => 路线 => 环境
【问题讨论】:
-
您要链接到哪个视图?请运行
rake routes并发布输出。 -
您所有的路线都是“获取”请求。您需要添加一个路由,它将表单中的数据“发布”到您要处理它的控制器和操作。例如。发布“输入输出/注册”
-
@AlejandroMontilla 我想将它链接到名为“micropost”的视图,该视图是名为 InputOutput 的控制器的一部分,该控制器还包含注册页面和登录页面。
-
@bkunzi01 我不太确定“发布”路线的确切格式应该是什么。如上一条评论所述,我希望按钮指向的视图称为“微博”。那么我应该如何构建这个?
-
控制器的名称和指向此视图的控制器的操作是什么?所有 Rails 视图都与一个控制器和该控制器中的一个动作相关联。告诉我们,我们可以为您提供路线。我强烈推荐一些关于 Rails 路由的教程。
标签: ruby-on-rails ruby model-view-controller routes