Ruby on rails 为嵌套资源使用回形针时出现命名错误
嗨,我是Rails的新手,在我尝试使用回形针之前,我设法让一些课程一起工作 在我尝试上传图片之前,一切正常。我得到这个错误:Ruby on rails 为嵌套资源使用回形针时出现命名错误,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,嗨,我是Rails的新手,在我尝试使用回形针之前,我设法让一些课程一起工作 在我尝试上传图片之前,一切正常。我得到这个错误: 未定义的方法“业务位置路径”# 以下是两种型号: class Business < ActiveRecord::Base attr_accessible :bizName, :contact, :email, :ownerName, :signupDate, :website has_many :businessLocations end class Busi
未定义的方法“业务位置路径”# 以下是两种型号:
class Business < ActiveRecord::Base
attr_accessible :bizName, :contact, :email, :ownerName, :signupDate, :website
has_many :businessLocations
end
class BusinessLocation < ActiveRecord::Base
belongs_to :business
attr_accessible :address1, :address2, :contact, :description, :email, :latitude, :longitude, :postal, :price, :mainpic
has_attached_file :mainpic, :styles => {:large => "640x640>", :medium => "320x320>", :thumb => "100x100>"}
end
表格:
<%
if params[:action] == "new"
urlpath = business_businessLocations_path(@business)
else
if params[:action] == "edit"
urlpath = business_businessLocation_path(@business,@businessLocation)
end
end
%>
<%= form_for @businessLocation, :url=>urlpath, :html =>{ :multipart => true } do |f| %>
...
<div class="field">
<%= f.label :mainpic %><br />
<%= f.file_field :mainpic %>
</div>
没有这样的路径business\u locations\u path,因为BusinessLocation嵌套在business中
编辑:以下是我的rake路线:
business_businessLocations GET /businesses/:business_id/businessLocations(.:format) businessLocations#index
POST /businesses/:business_id/businessLocations(.:format) businessLocations#create
new_business_businessLocation GET /businesses/:business_id/businessLocations/new(.:format) businessLocations#new
edit_business_businessLocation GET /businesses/:business_id/businessLocations/:id/edit(.:format) businessLocations#edit
business_businessLocation GET /businesses/:business_id/businessLocations/:id(.:format) businessLocations#show
PUT /businesses/:business_id/businessLocations/:id(.:format) businessLocations#update
DELETE /businesses/:business_id/businessLocations/:id(.:format) businessLocations#destroy
businesses GET /businesses(.:format)
businesses#index
POST /businesses(.:format)
businesses#create
new_business GET /businesses/new(.:format)
businesses#new
edit_business GET /businesses/:id/edit(.:format)
businesses#edit
business GET /businesses/:id(.:format)
businesses#show
PUT /businesses/:id(.:format)
businesses#update
DELETE /businesses/:id(.:format)
businesses#destroy
在控制器中,创建操作设置为重定向到
business\u businessLocation\u路径
。这是由用于生成嵌套脚手架的任何内容自动生成的。解决这个问题可能会解决您所有的问题。不。更改重定向无效。代码实际上在没有附件的情况下工作,但是回形针一直在询问业务位置路径。你也可以发布你的rake路线吗??
def create
respond_to do |format|
@business = Business.find(params[:business_id])
@businessLocation = @business.businessLocations.build(params[:business_location])
if @businessLocation.save
format.html { redirect_to(business_businessLocation_path(@business,@businessLocation),
:notice => 'Post was successfully created.') }
format.json { render :json => @businessLocation,
:status => :created, :location => @business }
else
format.html { render :action => "new" }
format.json { render :json => @businessLocation.errors,
:status => :unprocessable_entity }
end
end
end
business_businessLocations GET /businesses/:business_id/businessLocations(.:format) businessLocations#index
POST /businesses/:business_id/businessLocations(.:format) businessLocations#create
new_business_businessLocation GET /businesses/:business_id/businessLocations/new(.:format) businessLocations#new
edit_business_businessLocation GET /businesses/:business_id/businessLocations/:id/edit(.:format) businessLocations#edit
business_businessLocation GET /businesses/:business_id/businessLocations/:id(.:format) businessLocations#show
PUT /businesses/:business_id/businessLocations/:id(.:format) businessLocations#update
DELETE /businesses/:business_id/businessLocations/:id(.:format) businessLocations#destroy
businesses GET /businesses(.:format)
businesses#index
POST /businesses(.:format)
businesses#create
new_business GET /businesses/new(.:format)
businesses#new
edit_business GET /businesses/:id/edit(.:format)
businesses#edit
business GET /businesses/:id(.:format)
businesses#show
PUT /businesses/:id(.:format)
businesses#update
DELETE /businesses/:id(.:format)
businesses#destroy