質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

0回答

1039閲覧

Rails 4 / Actionmailer / Jqueryが機能しない

ymatt

総合スコア20

jQuery

jQueryは、JavaScriptライブラリのひとつです。 簡単な記述で、JavaScriptコードを実行できるように設計されています。 2006年1月に、ジョン・レシグが発表しました。 jQueryは独特の記述法を用いており、機能のほとんどは「$関数」や「jQueryオブジェクト」のメソッドとして定義されています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

0クリップ

投稿2018/08/25 10:43

前提・実現したいこと

Rails 4にて以下の要領でお問い合わせフォームを作成中です。
https://www.imd-net.com/column/1731/

発生している問題・エラーメッセージ

問い合わせ機能そのものではなく、jqueryが機能しない問題です。
使っているbootstrapのテンプレートの、ドロップダウンが機能しません。
以下ソースコードの通り、ホームと問い合わせページのみのシンプルな構造です。
turbolinksはアプリケーション全体で切ってあります。

該当のソースコード

route.rb

Rails.application.routes.draw do get 'contact' => 'inquiry#contact' post 'contact/confirm' => 'inquiry#confirm' post 'contact/thanks' => 'inquiry#thanks' root 'static_pages#home' match '/home', to: 'static_pages#home', via: 'get' end

inquiry_controller.rb

class InquiryController < ApplicationController def contact # 入力画面を表示 @inquiry = Inquiry.new render :action => 'contact' end def confirm # 入力値のチェック @inquiry = Inquiry.new(params[:inquiry]) if @inquiry.valid? # OK。確認画面を表示 render :action => 'confirm' else # NG。入力画面を再表示 render :action => 'index' end end def thanks # メール送信 @inquiry = Inquiry.new(params[:inquiry]) InquiryMailer.received_email(@inquiry).deliver # 完了画面を表示 render :action => 'thanks' end end

gemfile

source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.6' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks # gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # gem 'jquery-turbolinks' gem 'figaro' gem 'passenger' gem 'jquery-ui-rails' group :production do gem 'pg' gem 'rails_12factor' end group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' gem 'pry-rails' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end

application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require jquery_ujs //= require_tree .

試したこと

もともとホームでもjqueryの発火に問題があり、turbolinksを切ったら機能するようになりましたが、contactページでは変わらず、いろいろと調べたところ、以下の情報に行き着きました。

引用元 https://railsguides.jp/action_mailer_basics.html
"GET以外のリンクが機能するにはrails-ujsまたはjQuery UJSが必須です。また、これらはメイラーテンプレートでは機能しません(通常のGETリクエストが出力されます)。"

ソースコードの通り、rails-ujsはおそらく入っているはずです。
どなたか、ヒントをご教示いただければと思います。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問