2016-10-03 159 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