がすくいルートがそれぞれルビーon Railsのルートの変更は
Prefix Verb URI Pattern Controller#Action
replies GET /replies(.:format) replies#index
POST /replies(.:format) replies#create
new_reply GET /replies/new(.:format) replies#new
edit_reply GET /replies/:id/edit(.:format) replies#edit
reply GET /replies/:id(.:format) replies#show
PATCH /replies/:id(.:format) replies#update
PUT /replies/:id(.:format) replies#update
DELETE /replies/:id(.:format) replies#destroy
comments GET /comments(.:format) comments#index
から変更ルーティングを呼び出した後
resources :comments do
resources :replies
end
に
resources :comments
resources :replies
から私のroutes.rbをを変更しようとするとエラーにつながります
〜
Prefix Verb URI Pattern Prefix Verb URI Pattern Controller#Action
comment_replies GET /comments/:comment_id/replies(.:format) replies#index
POST /comments/:comment_id/replies(.:format) replies#create
new_comment_reply GET /comments/:comment_id/replies/new(.:format) replies#new
edit_comment_reply GET /comments/:comment_id/replies/:id/edit(.:format) replies#edit
comment_reply GET /comments/:comment_id/replies/:id(.:format) replies#show
PATCH /comments/:comment_id/replies/:id(.:format) replies#update
PUT /comments/:comment_id/replies/:id(.:format) replies#update
DELETE /comments/:comment_id/replies/:id(.:format) replies#destroy
edit_reply_pathのようなパスがもう機能しません。
undefined method `edit_reply_path'
EDIT: パスは新しいエラーが返信に/ _form.erbを発生し
comment_edit_reply_pathするためにそれを変更することにより固定した。
undefined method `replies_path' for #<#<Class:0x007ff3e8d9df08>:0x007ff3e0cd9458>
誤差は次の行のためのものである
<%= form_with(model: reply, local: true) do |form| %>
編集: これは、コントローラ
def create
@reply = @comment.replies.create(:user_id, :anonymous, :text, :post_id, :title).permit(:reply)
respond_to do |format|
if @reply.save
format.html { redirect_to @reply, notice: 'Reply was successfully created.' }
format.json { render :show, status: :created, location: @reply }
else
format.html { render :new }
format.json { render json: @reply.errors, status: :unprocessable_entity }
end
end
エンド
に私は新しいcomment.repliesレコードを作成し、_form.html.erbを提出しようとすると....私は、コンソールで次のエラーが表示されます。
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.2ms)
ArgumentError (wrong number of arguments (given 5, expected 0..1)):
app/controllers/replies_controller.rb:29:in `create'
エラーがこの行
@reply = @comment.replies.create(:user_id, :anonymous, :text, :post_id, :title).permit(:reply)
ような何かを宣言する必要があり、ここで
のform_for使い方モデル:@reply、url:[@comment、@reply]) –
form_forを使いたい場合は、<%= form_for [@comment、@reply] do%> –
それはあなたの提案の両方のための '未定義のメソッド' replies_path 'を与える – John