0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

link_toって奥が深いねって話(原因不明)

Last updated at Posted at 2020-10-14

アプリ開発中投稿ボタンを押したら投稿ページに遷移するようにlink_toで記述をしていた時

  <%= link_to "投稿", 'new_photo_path'%>

最初はこのように記述しました。
するといつものスクリーンショット 2020-10-15 3.30.59.png
この赤いエラー分が出ました。。

仮定

routes.rbがうまく記述できていない
綴りが間違えてる

routes.rbを確認しにきました

routes.rb
resources :photos, except: :index
  root to: 'photos#index'

resourcesでindexを除外していること以外に不思議な点はなく

rails routes

で確認しても問題はなし…

スクリーンショット 2020-10-15 3.35.14.png

綴りも間違えていない…

行ったこと

PrefixではなくController#Actionの方を記述した
new_photo GET /photos/new(.:format)

index.html.erb
<%= link_to "投稿", '/photos/new'%>

で解決しました…

追加

@scivola さんからのコメントで原因がわかりました
@scivola さんありがとうございました。
Prefixは''で囲むと文字列になってしまうようです…
なので自分の場合は文字列として認識されているようです

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?