Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails中提交新表单时,没有与[POST]匹配的路由_Ruby On Rails_Forms_Ruby On Rails 4_Routing_Rails Routing - Fatal编程技术网

Ruby on rails 在Rails中提交新表单时,没有与[POST]匹配的路由

Ruby on rails 在Rails中提交新表单时,没有与[POST]匹配的路由,ruby-on-rails,forms,ruby-on-rails-4,routing,rails-routing,Ruby On Rails,Forms,Ruby On Rails 4,Routing,Rails Routing,提交新表单时,我会收到“无路线匹配[发布]”的警告 ### /routes.rb ### resources :artists, controller: 'artists/artists', only: [:show] do member do resources :videos, controller: 'artists/videos', only: [:index, :new, :create, :edit, :update] end end ### /artists/v

提交新表单时,我会收到“无路线匹配[发布]”的警告

### /routes.rb ###

resources :artists, controller: 'artists/artists', only: [:show] do
  member do
    resources :videos, controller: 'artists/videos', only: [:index, :new, :create, :edit, :update]
  end
end

### /artists/videos/videos_controller.rb ###

class Artists::VideosController < ApplicationController
  before_action :set_artist

  def new
    @video = ArtistVideo.new
  end

  def create
    @video = @artist.create_artist_video(video_params)
    if @video.save
      redirect_to current_artist
    else
      render 'new'
    end
  end

   private
     def set_artist
       @artist = current_artist
     end
end

### /artists/videos/new.html.erb ###

<%= form_for(@video, url: new_video_path) do |f| %>
    <%= f.label :video_title, "title", class: "label" %>
    <%= f.text_field :video_title, class: "text-field" %>

    <%= f.label :video_description, "decription", class: "label" %>
    <%= f.text_field :video_description, class: "text-field" %>

    <%= f.label :youtube_video_url, "youtube url", class: "label" %>
    <%= f.text_field :youtube_video_url, class: "text-field" %>

    <%= f.submit "add video", class: "submit-button" %>
<% end %>

### rake routes ###

videos_path         GET      /artists/:id/videos(.:format)          artists/videos#index
                    POST     /artists/:id/videos(.:format)           artists/videos#create
new_video_path      GET      /artists/:id/videos/new(.:format)       artists/videos#new
edit_video_path     GET      /artists/:id/videos/:id/edit(.:format)  artists/videos#edit
video_path          PATCH    /artists/:id/videos/:id(.:format)       artists/videos#update
                    PUT      /artists/:id/videos/:id(.:format)       artists/videos#update
####/routes.rb###
资源:艺术家,管理员:“艺术家/艺术家”,仅:[:show]do
成员do
资源:视频,控制器:“艺术家/视频”,仅:[:索引,:新建,:创建,:编辑,:更新]
结束
结束
###/artists/videos/videos\u controller.rb###
类艺术家::VideosController<应用程序控制器
行动前:设置艺术家
def新
@video=ArtistVideo.new
结束
def创建
@视频=@artist.create_artist_video(视频参数)
如果@video.save
将_重定向到当前_艺术家
其他的
呈现“新”
结束
结束
私有的
def set_艺术家
@艺术家=当前艺术家
结束
结束
###/artists/videos/new.html.erb###
###耙道###
视频\路径GET/artists/:id/视频(:格式)艺术家/视频\索引
POST/artists/:id/视频(:格式)艺术家/视频#创建
新建_video_path GET/artists/:id/videos/new(:format)artists/videos#新建
编辑_video_path GET/artists/:id/videos/:id/edit(:format)艺术家/视频#编辑
视频\路径补丁/artists/:id/videos/:id(:format)艺术家/视频\更新
PUT/artists/:id/videos/:id(:format)艺术家/视频#更新
所以我不确定我做错了什么。我尝试过完全删除:index,这样视频路径就可以使用post方法,但我仍然有同样的问题

我正在使用“有很多方法”将视频链接到艺术家,如果这很重要的话


不确定是路由还是控制器代码出错。任何帮助都将不胜感激。

您正在指定一个路径
url:new\u video\u path
,但这是用于
视频的#new
,您需要的是创建路径,即
视频路径(@artist)
的帖子。由于它是一个嵌套资源,因此路径必须具有它可以从
@artist
实例获得的艺术家id

但是,更简单的方法是:

form_for[@artist, @video] do |f|

您正在指定一个路径
url:new\u video\u path
,但该路径用于
视频#new
,您需要的是创建路径,即
视频的帖子路径(@artist)
。由于它是一个嵌套资源,因此路径必须具有它可以从
@artist
实例获得的艺术家id

但是,更简单的方法是:

form_for[@artist, @video] do |f|