1
我已經使用此example在Rails 4中創建了一個聯繫表單。 但我想在我的應用程序的主/顯示頁面上顯示此聯繫表單。我怎樣才能做到這一點?在主頁上顯示導軌聯繫表格
routes.rb。
Rails.application.routes.draw do
resources :projects
resources :contacts, only: [:new, :create]
get 'welcome/index'
root 'welcome#index'
end
contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(params[:contact])
@contact.request = request
if @contact.deliver
flash.now[:error] = nil
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
end
感謝。
非常感謝!完美的作品! :) –