"Template is missing" 使用带有 Rails 的 jQuery 时出错



我试图在编辑帐户页面中添加头像到用户配置文件中的"添加用户头像"链接。

这是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和得到:

模板缺失

缺少模板头像/new with {:handlers=>[:erb,:rjs,:builder,: rhtml rxml):格式=> (html)::语言环境=>[:恩,en)}视图的路径"/home/ugur/rails_projects/deneme/app/视图","/home/ugur/rails_projects/deneme/app/视图","/home/ugur/rails_projects/deneme/flag_promotions/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_sample-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_promo-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_dash-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_api-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_auth-0.60.1/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/devise-1.3.3/app/视图","/home/ugur/.rvm/珠宝/ruby-1.9.2-p180/宝石/spree_core-0.60.1/app/视图"

我都快疯了。请帮助。

您正在调用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

在url /avatars

最新更新