好的,我已经搜索了其他可用的Stackoverflow问题,并尽我最大的努力来破译该问题,但是我陷入了僵局。我是一名PHP开发人员,但我只是在学习Ruby on Rails(第4条)。
我想尝试实现的目标:-发布驻留在“ Blog”族下的view index.html.erb文件中的表单(使用form_for)(因此控制器也称为Blog)-但我想要该表单POST到一个完全不同的控制器,而不是Blog控制器,而是POST到名为Feature的控制器(特别是到名为Feature的控制器中的create动作)
我知道我应该在form_for中使用:url组件,但是我确定我输入的语法错误,或者其他地方引起了错误。
原谅我的新手一无所知,我只是从Rails开始
我当前收到的错误消息:
Blog#index中的ArgumentError参数数量错误(1..2为3)提取的源(在第3行附近):
<h1>Blog main page, welcome</h1>
<% form_for :feature, @feature, :url => { :action => "create" } do |f| %>
<p>
<%= f.label :subject %><br>
<%= f.text_field :string %>
我有的代码:
Index.html.erb(坐在Blog系列下)
<h1>Blog main page, welcome</h1>
<% form_for :feature, @feature, :url => { :action => "create" } do |f| %>
<p>
<%= f.label :subject %><br>
<%= f.text_field :string %>
</p>
<p>
<%= f.label :author %><br>
<%= f.text_area :string %>
</p>
<p>
<%= f.label :title %><br>
<%= f.text_area :string %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<br>
<%= link_to "My Blog", new_blog_path %>
我具有功能控制器的代码
class FeatureController < ApplicationController
def index
end
def new
end
def show
end
def create
@feature = Blog.new (feature_params)
render text: params[:feature].inspect
end
private
def feature_params
params.require(:feature).permit(:title, :text, :text2, :text3)
end
end
end
我的路线配置中包含的代码
MyApp::Application.routes.draw do
root 'blog#index'
resources :blog
resources :admin
resources :feature
end
我的数据库架构如下所示:
create_table "blogs", force: true do |t|
t.string "subject"
t.string "title"
t.string "author"
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
我不知道我在做什么错:(如果有人能够帮助我,我将非常感激
将路由修改为使用复数格式后,解决方案是:
<%= form_for :features, :url => features_path do |f| %>
features_path
作为路径帮助方法 '/features'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句