2016-10-03 156 views
0

Udemy:訓練營課程:部分:8講座:122:節省數據:在「聯繫我們」頁面我填寫了信息,名稱:test1,電子郵件:[email protected],評論: test1,作爲一個測試,按下提交,但按鈕不提交信息,並沒有提供任何錯誤信息。我哪裏錯了?任何專家的建議?這裏是我的代碼:提交按鈕

class ContactsController < ApplicationController 
     def new 
     @contact = Contact.new 
     end 

     def create 
     @contact = Contact.new(contact_params) 

     if @contact.save 
      flash[:success] = 'Message sent.' 
      redirect_to new_contact_path 
     else 
      flash[:danger] = 'Error occured, message has not been sent.' 
      redirect_to new_contact_path 
     end 
     end 
    end 
    private 
    def contact_params 
     params.require(:contact).permit(:name, :email, :comments) 
    end 

    <div class="row"> 
     <div class="col-md-4 col-md-offset-4"> 
     <div class="well" 
      <%= form_for @contact do |f| %> 
      <div class="form-group"> 
       <%= f.label :name %> 
       <%= f.text_field :name, class: 'form-control' %> 
      </div> 

      <div class="form-group"> 
       <%= f.label :email %> 
       <%= f.email_field :email, class: 'form-control' %> 
      </div> 

      <div class="form-group"> 
       <%= f.label :comments %> 
       <%= f.text_area :comments, class: 'form-control' %> 
      </div> 
      <%= f.submit 'Submit', class: 'btn btn-default' %> 
     <% end %> 
     </div> 
     </div> 
    </div> 

回答

0

我不是一個鐵軌專家,但你可以試試<%= form_for(@contact, :method => :get) do |f| %>,應該得到它的工作。

在你contact.rb模型類型以下

class Contact < ActiveRecord::Base 

end 
+0

@Theo工作的呢? – angkiki

+0

angkiki - 我聯合你的建議代碼,但我得到這個錯誤: – Theo

+0

@Theo最新錯誤?我看不到它 – angkiki