所以我发了一个名为"教室#new"的页面。但是当我点击发送给它的按钮时,它不会显示出来。 以下是我的课堂路线: (routes.rb中)
get 'classrooms/index'
get 'classrooms/new'
以下是与之关联的按钮: (Nav_link_for_auth.html.erb)
<li><%= link_to 'Create a Class', 'classrooms#new' %></li>
此处的代码位于app / views / classrooms / new.html.erb
中<section class="newclass_form">
<%= render 'layouts/newclass_form' %>
</section>
表单网址:
<%= form_for :classroom, html: { multipart: true }, url: classrooms_new_path do |f| %>
<h2>Create a Class!</h2>
#additional code here
它有一条路线,所以为什么它不会出现? 非常感谢!
答案 0 :(得分:1)
我相信你想要:
<li><%= link_to 'Create a Class', 'classrooms/new' %></li>
如果您查看浏览器屏幕截图中的网址,您会看到
<li><%= link_to 'Create a Class', 'classrooms#new' %></li>
的产率:
https://kidznotes-app-cynthiarios.c9users.io/classrooms#new
但你想:
https://kidznotes-app-cynthiarios.c9users.io/classrooms/new
另外,我建议改变:
get 'classrooms/index'
get 'classrooms/new'
为:
resources :classrooms
然后我会这样做:
<li><%= link_to 'Create a Class', new_classroom_path %></li>
要链接到Classrooms#index
,您可以执行以下操作:
link_to 'Classrooms', classrooms_path
另外,我认为这是错误的:
<%= form_for :classroom, html: { multipart: true }, url: classrooms_new_path do |f| %>
<h2>Create a Class!</h2>
#additional code here
它会尝试提交到classrooms_new_path
,而您没有将其定义为路线。相反,尝试类似:
<%= form_for :classroom, html: { multipart: true } do |f| %>
<h2>Create a Class!</h2>
#additional code here