我想做一个简单的提交,理想情况下没有路线,将样本插入数据库,但我遇到了一些麻烦。
这是金融指数:
index.html.erb(财务路径)
<%= form_for(@place,:url => new_place_finance_path,:method => :put) do |f| %>
<%= f.text_field :place %>
<%= f.submit %>
<% end %>
如果可能的话我不想创建一个成员,我如何在路线中制作:
resources :finances do
member do
put :new_place
end
end
和我的财务总监:
def index
@finances = Finance.all
respond_with @finances
@place = Place.new
end
和行动 new_place:
def new_place
@place = Place.create(params[:place])
@place.save
if @place.save
redirect_to finances_path,:notice => 'Lugar criado com sucesso.'
else
redirect_to finances_path,:notice => 'Falha ao criar lugar.'
end
end
我收到此错误:
No route matches {:action=>"new_place", :controller=>"finances", :id=>nil}
当我执行 rake 路由时:
new_place_finance PUT /finances/:id/new_place(.:format) finances#new_place