我对铁杆比较陌生,但对我所知道的事情有一个真正的问题应该非常简单。我有一个名为channel的模型,在其中我有一个简单的新方法,在视图中我有表单,但每次我尝试加载它时,我都会收到错误说:
undefined method `channels_path'
我的观点(new.html.erb)非常简单,只要它有一个带有名称和值的按钮,它就像这样:
<%= simple_form_for @channel do |f| %>
<%= f.error_notification %>
<%= f.button :submit, 'Free Plan', name: 'plan', value: 'free' %>
<% end %>
我的控制器有:
def new
@channel = Channel.new
end
在我的路线中,我有:
resources :channel
rake路线的输出形式为:
channel_index GET /channel(.:format) channel#index
POST /channel(.:format) channel#create
new_channel GET /channel/new(.:format) channel#new
edit_channel GET /channel/:id/edit(.:format) channel#edit
channel GET /channel/:id(.:format) channel#show
PATCH /channel/:id(.:format) channel#update
PUT /channel/:id(.:format) channel#update
DELETE /channel/:id(.:format) channel#destroy
这一切看起来如我所料。但是因为错误说没有channels_path,但据我所知,应该没有。
我确信这应该是非常简单但我无法看清我做错了什么。有人可以帮忙吗?
非常感谢 大卫
编辑
我已将路线更新为:
resources :channels
我现在可以加载表单,但是我现在在尝试提交时遇到错误:
param is missing or the value is empty: channel
由以下原因引起:
# only allow specific params
def channel_params
params.require(:channel).permit(:name,
:slug,
:description,
:plan,
:subscription_ends
)
end
我假设基于模型这里的单数是正确的,但是也试过复数而没有运气。还有什么想法吗?
非常感谢
修改
最终有了它的工作,看来你的表单中必须至少有一个输入。我为名称字段添加了一个输入,它开始工作。
非常感谢评论的每个人