繁体   English   中英

Ruby on rails单位化常量

[英]Ruby on rails unitialized constant

我是Ruby on Rails的新手,我不太清楚这个错误意味着什么:

uninitialized constant StorevaluesController

我有一个storevalue_controller.rb可以工作(我可以访问页面上的内容)但是当我尝试提交这样的表单时:

new.html.erb

<h1>Fill out form to add to db</h1>
<%= form_for :storevalue, url: storevalue_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>

<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>

<p>
<%= f.submit %>
</p>
<% end %>

rails抛出我上面引用的错误。

storevalue_controller.rb

class StorevalueController < ApplicationController
def new
end
def create
@storevalue = Storevalue.new(storevalue_params)
@storevalue.save
redirect_to @storevalue
end

def show
@storevalue = Storevalue.find(params[:id])
end

private
def storevalue_params
params.require(:storevalue).permit(:title, :text)
end
end

我的路线追踪:

welcome_index_path    GET   /welcome/index(.:format)    welcome#index
root_path             GET   /   welcome#index
storevalue_new_path   GET   /storevalue/new(.:format)   storevalue#new
storevalue_path       POST  /storevalue(.:format)   storevalues#create
new_storevalue_path   GET   /storevalue/new(.:format)   storevalues#new
edit_storevalue_path  GET   /storevalue/edit(.:format)  storevalues#edit
GET     /storevalue(.:format)   storevalues#show
PATCH   /storevalue(.:format)   storevalues#update
PUT     /storevalue(.:format)   storevalues#update
DELETE  /storevalue(.:format)   storevalues#destroy

请注意,错误是多个“值”,而实际的控制器名称则不是。 当它不存在时,你在某处使用复数名称。 在Ruby中,类名是常量。 因此,您有错误信息措辞,我同意这在表面上非常误导。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM