Rails でプログラミングをするのは久しぶりです... Rails 5.0 のすべての構文と変更点について最新情報を取得しています。
Rails 5.0.0.1 の使用
Ruby を使用する ruby 2.3.1p112 (2016-04-26 リビジョン 54768) [x86_64-darwin16]
ランディングページに簡単なお問い合わせフォームを設定しようとしています。フォームから直接メールを送信するのではなく、データベースに保存するというルートをたどっています。
私はmail_form gem を使用しており、このスレッドに従っています
コントローラーで初歩的なミスを犯していることはわかっていますが、いくつかのスタック Q/A を行った後でも、まだ完全には達成できていません。
モデルは Rails コンソールで正常に電子メールを送信しています。ただコントローラーが動かない。これは 1 ページのサイトなので、Pages View フォルダの Index ページにパーシャルを追加しています。
私が得ているエラー
AbstractController::ActionNotFound (The action 'create' could not be found for PagesController):
ルート
Rails.application.routes.draw do
get 'users/new'
resources :pages
root 'pages#index'
end
部分的なフォーム
アプリ/ビュー/ページ/_form.html.erb
<%= form_tag(pages_path) do %>
<div class="row">
<div class="column width-6">
<%= text_field_tag 'firstname', nil, class: 'form-element rounded large', placeholder: 'First Name*', tabindex: '1' %>
</div>
<div class="column width-6">
<%= text_field_tag 'lastname', nil, class: 'form-element rounded large', placeholder: 'Last Name*', tabindex: '2' %>
</div>
<div class="column width-6">
<%= email_field_tag 'email', nil, class: 'form-element rounded large', placeholder: 'Email Address*', tabindex: '3' %>
</div>
<div class="column width-6">
<%= text_field_tag 'website', nil, class: 'form-element rounded large', placeholder: 'Website', tabindex: '4' %>
</div>
<div class="column width-6">
<%= text_field_tag 'phone', nil, class: 'form-element rounded large', placeholder: 'Phone', tabindex: '5' %>
</div>
</div>
<div class="row">
<div class="column width-12">
<%= text_area_tag 'message', nil, class: 'form-element rounded large', placeholder: 'Message*', tabindex: '6' %>
</div>
<div class="column width-12">
<%= submit_tag 'Send Email', class: 'form-submit button rounded medium bkg-theme bkg-hover-green color-white color-hover-white' %>
</div>
</div>
<% end %>
ページコントローラー
class PagesController < ApplicationController
def index
@contact = Page.new(params[:page])
if @contact.deliver
redirect_to :back, :notice => "Thank you for contacting us, We'll get back to you shortly!"
else
flash.now[:error] = 'Sorry, it looks like there was an error with your message, Please give us a call or shoot us a text at ....'
end
end
end
助けてくれてありがとう。このコミュニティは素晴らしいです!