初めまして。
現在railsで簡単なブログ投稿アプリを実装しているのですが、
ブログの保存機能が実装できません。
保存しようとすると、undefined local variable or method `topic_paramsのNameerrorが吐き出されます。
一度、scaffoldで進めていたのですが、コードが読みづらくなり、最初から作り直していたところ
詰まってしまいました。
お時間を取らせてしまい申し訳ありませんが、お知恵を頂戴できましたら幸いです。
github: https://github.com/takeshi-kushima/otetsudai-netto
コントローラーのコードは以下になります。
class TopicsController < ApplicationController before_action :set_topic, only: [:show, :edit, :update, :destory] def index @topics = Topic.all end def new @topic = Topic.new end def show end def create @topic = Topic.new(topic_params) respond_to do |format| if @topic.save format.html { redirect_to @topic, notice:'あなたの募集ページを登録しました' } format.json { render :show,status: :created, location: @topic} else format.html {render :new } format.json {render json: @topic.erros,status: :unprocessable_entity} end end end def edit end def update respond_to do |format| if @topic.update(topic_params) format.html {redirect_to @topic, notice:'あなたの募集ページを更新しました' } else format.html {render :edit } end end def destory @topic.destroy respond_to do |format| format.html {redirect_to topics_url, notice:'あなたの募集ページを削除しました' } end end private def set_topic @topic = Topic.find(params[:id]) end def topic_params params.require(:topic).permit(:title, :company_name, :what, :glad, :please, :age, :human, :work, :day, :memo) end end end
route.rb
Rails.application.routes.draw do get 'home/top' resources :topics end
よろしくお願いいたします。
あなたの回答
tips
プレビュー