ruby on rails で開発を進めるうちに、コントローラの見通しをよくするため、管理側とユーザー側でフォルダ分けしたいと考えています。
クラス名やルートの設定は変更したのですが、新規作成
後のリダイレクトで下記のエラーが発生します。
NoMethodError in Admin::HogeController#create
undefined method `hoge_url' for #Admin::HogeController:0x007fa53fa80188
原因はviews/admin/hoge/_form.html.erbの
26 def create
27 @hoge = TempAnime.new(temp_anime_params)
28
29 respond_to do |format|
30 if @hoge.save
31 format.html { redirect_to @hoge, notice: 'Temp anime was successfully created.' }
32 format.json { render :show, status: :created, location: @hoge }
33 else
34 format.html { render :new }
35 format.json { render json: @hoge.errors, status: :unprocessable_entity }
36 end
37 end
38 end
この31行目redirect_to @hogeを
redirect_to admin_hoge_url(id:@hoge.id)
とすれば正常に動くのですが、redirect_to @hodeで何故hoge_urlメソッドを実行しようとするのでしょうか?
できれば
redirect_to @hodeでadmin_hoge_url(id:@hoge.id)、
link_to @hogeでadmin_hode_path(@hoge.id)に遷移するように設定したいです。
回答1件
あなたの回答
tips
プレビュー