###前提・実現したいこと
railsでslackへの通知を実装したく、以下の記事を参考に実装してみたのですが、
slack-notifierでrailsからSlackへ簡単にメッセージを送る
エラーになってしまいます。
###ソースコード
該当部分だけ抜き出すと以下のようです。
books_controller.rb
class BooksController < ApplicationController before_action :set_book, only: [:show, :edit, :update, :destroy] # GET /books # GET /books.json def index @books = Book.all end # GET /books/1 # GET /books/1.json def show end # GET /books/new def new @book = Book.new end # GET /books/1/edit def edit end # POST /books # POST /books.json def create @book = Book.new(book_params) respond_to do |format| notifier = Slack::Notifier.new "https://hooks.slack.com/services/hogehoge" notifier.ping "Hello World" if @book.save format.html { redirect_to @book, notice: 'Book was successfully created.' } format.json { render action: 'show', status: :created, location: @book } else format.html { render action: 'new' } format.json { render json: @book.errors, status: :unprocessable_entity } end end end
エラーコード
NameError in BooksController#create uninitialized constant BooksController::Slack
以下の箇所でエラーが出ています。
notifier = Slack::Notifier.new "https://hooks.slack.com/services/hogehoge"
githubのドキュメントでは例として
require 'slack-notifier' notifier = Slack::Notifier.new "WEBHOOK_URL" notifier.ping "Hello World" # => if your webhook is setup, will message "Hello World" # => to the default channel you set in slack
とありますが、require 'sladk-notifier'
は何処に記述すれば良いのでしょうか?
Rails 4.0.2を使用しています。
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。