Ruby on rails 在主页上显示Rails联系人表单
我已经在Rails 4中创建了一个联系人表单,使用此 但是我想在我的应用程序的主页/显示页上显示此联系人表单。我该怎么做 routes.rb.Ruby on rails 在主页上显示Rails联系人表单,ruby-on-rails,ruby,Ruby On Rails,Ruby,我已经在Rails 4中创建了一个联系人表单,使用此 但是我想在我的应用程序的主页/显示页上显示此联系人表单。我该怎么做 routes.rb. Rails.application.routes.draw do resources :projects resources :contacts, only: [:new, :create] get 'welcome/index' root 'welcome#index' end 联系控制器.rb class ContactsContr
Rails.application.routes.draw do
resources :projects
resources :contacts, only: [:new, :create]
get 'welcome/index'
root 'welcome#index'
end
联系控制器.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
class contacts控制器
谢谢。创建一个 _联系_form.html.erb(Partials总是以下划线开头) 然后,在索引页中:
<%= render "contacts/contact_form" %>
最后,您似乎对rails很陌生,我想推荐一种免费的、简单而干净的方法,创建一个 _联系_form.html.erb(Partials总是以下划线开头) 然后,在索引页中:
<%= render "contacts/contact_form" %>
最后,您似乎对rails很陌生,我想推荐一个免费的非常感谢!很好用!:)谢谢!很好用!:)
def index
#your code
@contact = Contact.new
end