2011-08-10 51 views
1

我试图在编辑帐户页面中使用“添加用户头像”链接为用户个人资料添加头像。“Template is missing”错误使用jQuery与Rails

这是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!!!') 

我使用的铁轨3.0.9和获得:

模板丢失

缺少模板化身/新与{:处理器=> [:ERB,:RJS,:建设者, “/ home/ugur/rails_projects/deneme/app/views”中查看路径 :rhtml,:rxml],:formats => [:html],:locale => [:en,:en]/home/ugur/rails_projects/deneme/app/views“, ”/ home/ugur/rails_projects/deneme/flag_promotions/app/views“, ”/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

你有一个 '编辑' 的方法?您链接到edit_avatar_path。不要create_avatar_path – Bjoernsen

回答

2

您正在调用edit操作并希望create模板被呈现。这才是重点。

鉴于您的输出,我猜0123Å行动是呈现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

+0

@macfan_:有何评论?不要忘记接受一个答案,如果它适合 – apneadiving

+0

对不起,我发布了错误的链接。它被纠正了。请看一看。 –

+0

好吧,但同样的结论:你叫新的行动,所以部分应该是new.js.erb – apneadiving