2015-01-07 30 views
0

我還有很長的形式與我們的數據庫中的信息自動填充(基於由用戶提供的部分信息)。當用戶驗證信息並重新提交表單時,信息應該保存爲用戶。表單 - qualifying_events - 是視圖/共享文件夾中的一部分。該自動填充它的數據由qualifying_events_controller呈現爲創建方法的一部分。該部分被呈現用於在由用戶控制器呈現的視圖/用戶頁面中進行驗證。由用戶輸入的初始部分信息 - 在同一頁面上的相似部分 - 正確保存。這裏的表單頂部:的form_for得到呈現,而不是後,使用Rails

<form class="form-inline"> 
    <%= form_for(@qualifying_event) do |f| %> 
    <%= render 'shared/error_messages', object: f.object %> 
<div > 
    <div class="form-group col-sm-12 text-center" style="margin-bottom: 5px;"><h5> 
    <div> 
     <li style="list-style-type: none; float: left; display: none; visibility: hidden;"> 
     <%= current_user %> 
     </li> 
    </div> 
    <div> 
     <li style="list-style-type: none; float: left;"> 
     <%= f.label :class_date %><br/> 
     <%= f.text_area :class_date, autofocus: true %> 
     </li> 
    </div> 

以下是錯誤消息:

No route matches [GET] "/qualifying_events" 

這裏就是我已經試過:
1.明確添加路由到config/routes文件雖然已經表明,如果我跑耙路線:

post 'qualifying_events_path'  => 'qualifying_events#create' 


2.更改的form_for語言來顯式調用「後':

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

我仍然收到相同的錯誤信息。因爲我有其他的形式被保存到數據庫中使用相同的代碼,我必須假設當窗體從數據庫中填充有新的變化,而且用戶希望重新保存的信息。我使用的是色器件寶石,所以我看了看登記#編輯代碼,希望我能遵循以下格式:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 

不幸的是,這種方法也不能工作。

對於「完整性」,這裏的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 

有可能是在「其他」語句錯誤。我還沒有添加代碼來驗證所有需要的信息存在,等等

我可以保存並從數據庫中檢索信息,但是一個編輯的信息,重新提交要求「得到」而非「後「。我錯過了什麼?先謝謝你。

回答

0

拆下<form class="form-inline">(以及結束標記如果有的話)之前form_for。 HTML表單不能嵌套,從而只有外形式加工是具有GET方法。

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

到:

+0

謝謝。這是問題。 – user3763682

1

從刪除第一個<form>元素並修復form_for代碼

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