如何解决联系表单 Rails 6 问题
我在 Rails 6 中的联系表单有一些问题,我不知道我做错了什么,所以这里有一些信息。顺便说一下,我试过这个教程ContactForm。
控制台给我看这个:
Completed 200 OK in 309ms (Views: 303.7ms | ActiveRecord: 0.0ms | Allocations: 26852)
Started POST "/contacto" for 127.0.0.1 at 2021-01-14 21:14:38 -0600
AbstractController::ActionNotFound (The action 'route_not_found' could not be found for ApplicationController):
actionpack (6.0.3.4) lib/abstract_controller/base.rb:131:in `process'
简单形式:
<%= form_for( @contact,url: contacto_path,:html => {class: "content-area content-area-form"}) do |f| %>
<div class="fields-wrap">
<span type="text" id="eyeball1"><div class="eye"></div></span>
<%= f.label :name,class: "full-name-label" %>
<%= f.text_field :name,requiered: true,placeholder: "Tu nombre completo.",autocomplete: "off"%>
<div id="beam1" class="beam"></div>
</div>
<div class="fields-wrap">
<span type="text" id="eyeball2"><div class="eye"></div></span>
<%= f.label :email,class: "email-label" %>
<%= f.text_field :email,placeholder: "Tu e-mail.",autocomplete: "off"%>
<div id="beam2" class="beam"></div>
</div>
<div class="fields-wrap">
<span type="text" id="eyeball3"><div class="eye"></div></span>
<%= f.label :message,class: "desc-area-label"%>
<%= f.text_area :message,rows: 8,cols: 30,required: true,placeholder: "Tu mensaje.",autocomplete: "off" %>
</div>
<%= f.submit 'Enviar',class: "send-button" %>
<% end %>
控制器
class ContactsController < ApplicationController
before_action :contact_params,only: [:create]
def index
@contact = ContactForm.new
end
def create
@contact = ContactForm.new(params[:contact_form])
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Thank you for your message!'
render :index
else
flash.now[:error] = 'Cannot send message.'
render :index
end
end
private
def contact_params
params.require(:contact_form).permit(:name,:email,:message)
end
end
和路由应用
Rails.application.routes.draw do
#root 'my_app#proximamente'
root 'my_app#home'
get '/promos',to: 'my_app#promo'
get '/contacto',to: 'my_app#contact'
match '*unmatched',to: 'application#route_not_found',via: :all
end
MailForm::Base 注意:这是唯一可以完美运行的代码,我之前证明过就像 MailForm gem 的教程所说的那样。
class ContactForm < MailForm::Base
attributes :name,:validate => true
attributes :email,:validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attributes :message,:validate => true
def headers
{
:subject => "Contacto de ejemplo",:to => "trainer@bodyfuss.com",:from => %("#{name}" <#{email}>)
}
end
end
我希望你能给我一些想法或我的谜语的解决方案,非常感谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。