没有路由匹配“/subscribers/create”
我从我正在阅读的一本书中复制了此内容,并遵循了所有说明,但它给了我 No Route matches "/subscribers/create" 错误:
def create
if request.post?
@subscriber = Subscriber.new(:email => params[:email])
if @subscriber.save
@success = "Thank you, You have been subscribed."
else
@error = @subscriber.errors.full_messages[0]
end
end
请注意,这本书是为 Rails v2 编写的,而我正在使用 v3。
怎么了?
I copied this from a book I'm reading and I followed all the instructions but it's giving me No route matches "/subscribers/create" error:
def create
if request.post?
@subscriber = Subscriber.new(:email => params[:email])
if @subscriber.save
@success = "Thank you, You have been subscribed."
else
@error = @subscriber.errors.full_messages[0]
end
end
Please note that the book is written for Rails v2 and I'm using v3.
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的代码缺少 END。
另外,不需要指定是否request.post?
Rails 会自动将 POST 请求路由到 create 方法
The code you posted is missing an END.
Also, no need to specify if request.post?
Rails will automatically route a POST request to the create method