【发布时间】:2015-05-29 15:51:28
【问题描述】:
嘿,我正在尝试为我的 rails 应用程序创建一个联系页面。我创建了一个联系人模型:
class Contact < ActiveRecord::Base
end
联系人控制器:
class ContactsController < ApplicationController
skip_after_action :verify_authorized
def new
@contact = Contact.new
end
def create
end
end
运行迁移:
class CreateContacts < ActiveRecord::Migration
def change
create_table :contacts do |t|
t.string :email
t.string :object
t.text :content
t.timestamps null: false
end
end
end
我还创建了一条路线
resources :contacts, only: [:new, :create]
并创建了一个视图:
<div class="banner">
<div class="container">
<div class= "col-xs-12">
<%simple_form_for @contact do |t|%>
<%= t.error_notification %>
<%= t.input :email, label: 'Votre email' %>
<%= t.input :object, label: 'Objet' %>
<%= t.input :content, label: 'Votre Message' %>
<%= t.button :submit, value: "Soumettre ce tournoi à validation", class: "btn-primary marge-bas" %>
<% end -%>
</div>
</div></div>
指向我的联系人/新联系人的链接可以正常工作,但我的联系人表单未显示在页面上。
【问题讨论】:
-
<%simple_form_for @contact do |t|%>等于在此行前面缺少 -
应该是
<%=simple_form_for @contact do |t|%> -
谢谢,我想我需要停止编码几个小时:/
-
这是一个非常常见的错误...建议您删除此帖子..否则您可能不得不面对太多的负面投票:)
标签: html ruby-on-rails simple-form