form_for使用rails渲染而不是发布

我有一个很长的表单,自动填充来自我们数据库的信息(基于用户提供的部分信息)。 当用户validation信息并重新提交表单时,信息应保存为用户。 表单 – qualifying_events – 是views / shared文件夹中的部分。 自动填充它的数据由qualifying_events_controller作为create方法的一部分呈现。 部分用于在由用户控制器呈现的视图/用户页面中进行validation。 用户输入的初始部分信息 – 在同一页面上的类似部分 – 正确保存。 这是表单的顶部:


  • 这是错误消息:

     No route matches [GET] "/qualifying_events" 

    这是我尝试过的:
    1.显式添加到config / routes文件的路由,尽管已经显示我是否运行了rake路由:

     post 'qualifying_events_path' => 'qualifying_events#create' 

    2.更改form_for语言以显式调用’post’:

      post) do |f| %> 

    我仍然得到相同的错误消息。 由于我有其他使用相同代码保存到数据库的表单,因此当从数据库填充表单并且想要重新保存信息时,我必须假设有些更改。 我正在使用设计gem,所以我看了注册#编辑代码,希望我可以遵循以下格式:

       

    不幸的是,这种方法也不起作用。

    对于’完整性’,这是qualifying_events_controller代码:

     def create @user = current_user @qualifying_event = current_user.qualifying_events.build(qualifying_event_params) if @qualifying_event.validated.nil? # Match partial course information from current_user with records in table # Get partial record's information active_date = @qualifying_event.class_date active_course = @qualifying_event.course_id active_sponsor = @qualifying_event.sponsor_name # Match on class_date, course_id, and sponsor_name @qualifying_event = QualifyingEvent.new @qualifying_event.assign_attributes(QualifyingEvent. where("(class_date = :class_date AND course_id = :course_id) OR (class_date = :class_date AND sponsor_name = :sponsor_name) OR (course_id = :course_id AND sponsor_name = :sponsor_name)", {class_date: active_date, course_id: active_course, sponsor_name: active_sponsor}).first.attributes) # render to confirmation form / form for completion flash[:success] = "Qualifying Event saved for verification!" respond_to do |format| format.html {render 'users/user_dashboard' } end else # if the record is complete @qualifying_event.save flash[:success] = "Qualifying Event created!" redirect_to user_dashboard_path end 

    ‘else’语句中可能存在错误。 我还没有添加代码来validation是否存在所有必需的信息等。

    我可以保存并从数据库中检索信息,但是重新提交已编辑的信息会调用“获取”而不是“发布”。 我错过了什么? 先感谢您。

    form_for之前删除

    (以及结束标记,如果有的话)。 HTML表单不能嵌套,因此只处理具有GET方法的外部表单。

    删除第一个

    元素并修复form_for代码:

     <%= form_for(@qualifying_event, url: qualifying_events_path, method: => post) do |f| %> 

    至:

     <%= form_for(@qualifying_event, url: qualifying_events_path, method: :post, class: 'form-inline') do |f| %>