gpt4 book ai didi

ruby-on-rails - Ruby on Rails Form_for 错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:23:57 25 4
gpt4 key购买 nike

我正在用 Ruby on Rails 制作一个游戏作为学校项目,但现在我遇到了这个错误:

#<#:0x007ff34cca8f68> 的未定义方法“storylines_index_path”

我正在制作一个页面,您希望在其中添加一个表单来添加故事情节,因此我需要一个包含一些字段的表单。我想使用 form_for 方法。但是在添加时出现此错误

这是我的代码:

views/new.html.erb

<% provide(:title, 'Overzicht Storylines') %> 
<h1>Voeg nieuwe storyline toe</h1>
<%= form_for(@storyline) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :title %>
<%= f.text_field :title%>

<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>

<% end %>

storylines_controller.rb

class StorylinesController < ApplicationController   def index
@storylines = Storylines.find(:all) end

def show
@storyline = Storylines.find(params[:id])
end

def new
@storyline = Storylines.new end end

故事情节.rb

class Storylines < ActiveRecord::Base   
attr_accessible :title, :text
end

路线.rb

StoryLine::Application.routes.draw do   
get "users/new"
get "storylines/new"

resources :users
resources :storylines
resources :sessions, only: [:new, :create, :destroy]

match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete

root to: 'static_pages#home'

match '/help', to: 'static_pages#help'
match '/contact', to: 'static_pages#contact'
match '/about', to: 'static_pages#contact'
match '/home', to: 'static_pages#home'

end

最佳答案

Rails 约定要求您以单数形式命名您的模型,即 Storyline 而不是 Storylines。在类定义和 Controller 中重命名您的模型名称应该可以解决此问题。

关于ruby-on-rails - Ruby on Rails Form_for 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com