除非我刷新页面form_for Rails,否则提交按钮不起作用

我有一个有问题模型的应用程序,当我去创建一个记录时,提交按钮什么都不做。 除非我刷新页面并尝试再次添加它,否则没有错误只是根本不执行。 当我更新记录时也会发生同样的情况。

这是我的控制器

class ProblemsController < ApplicationController include Concerns::Votes def index @problems = Problem.all end def show @problem = find_problem end def new @problem = Problem.new end def edit @problem = find_problem end def create @problem = current_user.problems.new(problem_params) @problem.save redirect_to @problem end def update @problem = find_problem if @problem.update_attributes(problem_params) redirect_to @problem else redirect_to @problem end end private def find_problem @problem = Problem.find(params[:id]) end def problem_params params.require(:problem).permit(:name, :description, :url) end end 

这是我在new.html上呈现的_form.html.erb部分

 

我有资源:我的路线有问题。

好的方法是我的show.html.erb。

   

()

<a =href"">

By
<a class="button" 'problems', :action => 'up_vote'}, {:method => :post } %> <a class="button" 'problems', :action => 'down_vote'}, {:method => :post } %> |

这是我的index.html.erb

 

如果我刷新页面,我真的无法理解它为什么会起作用,否则它根本不起作用。

您的HTML无效,提交按钮实际上没有嵌套在表单标记下。 尝试将您的视图代码更改为:

 
<%= form_for @problem do |f| %> <%= f.text_field :name, placeholder: "Name your problem!" %>
<%= f.text_field :url, placeholder: "Link to any supporting material" %>
<%= f.text_area :description %>
<%= f.submit "Create" %>
<% end %>

我有同样的问题

之前

 <%= simple_form_for(:schedule_list, url: schedulelists_create_with_block_path, :html => { novalidate: false}) do |f| %> 
<%= f.button :submit, class: 'pull-right' %> <%end%>

 <%= simple_form_for(:schedule_list, url: schedulelists_create_with_block_path, :html => { novalidate: false}) do |f| %> 
<%= f.button :submit, class: 'pull-right' %>
<%end%>