我正在创建一个用户可以创建的应用程序和@idea,然后另一个@user可以' fork' @idea。为此,我使用了重复的方法ActiveRecord::Core#dup。
这就是我想要发生的事情。 @user打开了@idea显示页面并点击了一个图标,该图标应该引导他/她进入一个新的@forked_idea编辑页面,这将允许他们编辑原始的@idea并将其保存为新的@forked_idea。
以下是原始@idea的显示页面的片段。点击图标后,我希望它能够路由到一个编辑页面(在想法中或在想法中)
<%= link_to "<i class='fa fa-code-fork fa-5x'></i>".html_safe, idea_forked_idea_path(@idea), method: :get %>
当我点击图标来分叉@idea时,我看到了这个错误:
ActionController::UrlGenerationError - No route matches {:action=>"update", :controller=>"forked_ideas", :format=>nil, :id=>nil, :idea_id=>#<Idea id: 78,
这是app / controllers / ideas_controller.rb
class ForkedIdeasController < ApplicationController
def edit
end
def update
@idea = Idea.find(params[:id])
@forked_idea = @idea.dup
if @forked_idea.save(forked_idea_attributes)
redirect_to forked_ideas_edit_path(@idea), notice: "Forking this idea!"
else
render ideas_path
end
end
def destroy
if @idea.destroy
redirect_to ideas_path, notice: "idea has been deleted"
else
redirect_to ideas_path, notice: "idea has been deleted"
end
end
private
def forked_idea_attributes
params.require(:forked_idea).permit([:title, :body, :tag_list, :image])
end
end
端
我的forked_idea模型:
class ForkedIdea < ActiveRecord::Base
belongs_to :user
路线
resources :ideas do
resources :forked_ideas, only:[:edit, :update, :destroy]
end
以下是rake routes
edit_idea_forked_idea GET /ideas/:idea_id/forked_ideas/:id/edit(.:format) forked_ideas#edit
idea_forked_idea PATCH /ideas/:idea_id/forked_ideas/:id(.:format) forked_ideas#update
PUT /ideas/:idea_id/forked_ideas/:id(.:format) forked_ideas#update
DELETE /ideas/:idea_id/forked_ideas/:id(.:format) forked_ideas#destroy
ideas GET /ideas(.:format) ideas#index
POST /ideas(.:format) ideas#create
new_idea GET /ideas/new(.:format) ideas#new
edit_idea GET /ideas/:id/edit(.:format) ideas#edit
idea GET /ideas/:id(.:format) ideas#show
PATCH /ideas/:id(.:format) ideas#update
PUT /ideas/:id(.:format) ideas#update
DELETE /ideas/:id(.:format) ideas#destroy
答案 0 :(得分:0)
可能是“id”为零 - 给出错误信息:
ActionController::UrlGenerationError - No route matches {:action=>"update", :controller=>"forked_ideas", :format=>nil, :id=>nil, :idea_id=>#<Idea id: 78,
当“id”为零时,您似乎没有路线。