我正在尝试使用修改帐户页面中的“添加用户头像”链接向用户个人资料添加头像。
这是avatars_controller.rb:
def new
@avatar = Avatar.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @avatar }
format.js
end
end
def create
@avatar = @user.avatars.create(params[:avatar])
respond_to do |format|
if @avatar.save
format.html { redirect_to(edit_account_path, :notice => 'Avatar was successfully created.') }
format.xml { render :xml => @avatar, :status => :created, :location => @avatar }
format.js
else
format.html { render :action => "new" }
format.xml { render :xml => @avatar.errors, :status => :unprocessable_entity }
format.js
end
end
end
这是我的链接:
<%= link_to "add a new avatar", new_avatar_path%>
路线:
resources :avatars
resources :users do
resources :avatars
end
视图/化身/ create.js.erb:
alert('whoaaa!!!')
我正在使用rails 3.0.9并获得:
缺少模板
我快要疯了。请帮忙。缺少模板头像/新的{:handlers =&gt; [:erb,:rjs,:builder, :rhtml,:rxml],:formats =&gt; [:html],:locale =&gt; [:en,:en]}在视图路径中 “/家庭/ UGUR / rails_projects / deneme /应用/视图” “/家庭/ UGUR / rails_projects / deneme /应用/视图” “/家庭/ UGUR / rails_projects / deneme / flag_promotions /应用/视图” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_sample-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_promo-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_dash-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_api-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_auth-0.60.1/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.3.3/app/views” “/home/ugur/.rvm/gems/ruby-1.9.2-p180/gems/spree_core-0.60.1/app/views”
答案 0 :(得分:2)
您正在调用edit
操作并希望呈现create
模板。这就是重点。
根据您的输出,我猜edit
操作正在呈现不存在的new.js.erb
模板。
变化:
<%= link_to "add a new avatar", new_avatar_path%>
使用:
<%= link_to "add a new avatar", new_avatar_path, :remote => true %>
实际发出ajax请求。
我在这里提交:https://github.com/apneadiving/avatars/commit/f88ebf3f65e2ad88176cd28f09fd9dc91448cb98
适用于网址/avatars