2016-07-30 64 views
-1

缺少模板admin/citizens/create,admin/application/create,application/create with {:locale => [:en],:formats => [:html] ,:variants => [],:handlers => [:erb,:builder,:raw,:ruby,:coffee,:haml,:jbuilder,:rabl]}。搜索:*「/ Users/aa/Sites/Active Shehri/activeshehri-mongo/app/views」*「/Users/aa/.rvm/gems/[email protected]/gems/wiselinks-1.2.1/app/views「*」/Users/aa/.rvm/gems/[email protected]/gems/rails_admin-0.6.6/app/views「*」/Users/aa/.rvm/gems/ruby [email protected]/gems/kaminari-0.16.1/app/views「*」/Users/aa/.rvm/gems/[email protected]/gems/devise_invitable-1.5.5/app/views 「*」/Users/aa/.rvm/gems/[email protected]/gems/twitter-bootstrap-rails-3.2.2/app/views「*」/Users/aa/.rvm/gems/ruby [email protected]/gems/devise-3.4.1/app/views」創建新用戶時出現Missing Template錯誤

.....這裏是代碼

= form_for [:admin, @user] do |f| 
    .row 
    .col-lg-6 
     .panel 
     .panel-heading Edit Landmark 
     .panel-body 
      .form-group 
      = f.label :first_name 
      = f.text_field :first_name, class: 'form-control' 
      .form-group 
      = f.label :last_name 
      = f.text_field :last_name, class: 'form-control' 
      .form-group 
      = f.label :email 
      = f.text_field :email, class: 'form-control' 
      .form-group 
      = f.label :gender 
      = f.text_field :gender, :class => 'form-control' 
      .form-group 
      = f.label :contact_no 
      = f.text_field :contact_no, :class => 'form-control' 
      .form-group 
      = f.label :address 
      = f.text_field :address, class: 'form-control' 
     = f.submit 'Save', class: 'btn btn-primary btn-submit btn-lg pull-right' 
     = link_to "Back", admin_home_user_panel_path, class: 'btn btn-primary btn-submit btn-lg pull-left' 
+0

使用redirect_to或呈現on ce對象保存在您的創建操作中。因爲您沒有create.html.erb –

+0

您確定您的app/views/admin/citizen文件夾中有create.html –

+0

已使用redirect_to admin_home_user_panel_path –

回答

0

我認爲你需要添加其他部分來處理用戶不保存時

def create 
    @user = User.new(new_params) 
    if @user.save 
    redirect_to admin_home_user_panel_path 
    else 
    #do render or redirect_to 
    end 
end 
+0

是的,當我把代碼中的其他部分重定向到新頁面。但它創建我的用戶爲什麼不保存它?爲什麼@ user.save不工作? –

+0

可能是你有一些驗證錯誤。在其他部分使用渲染。所以缺少模板錯誤現在不見了 –

0

的錯誤是因爲... e您的views/admin/citizens文件夾中沒有名爲create.html.erb的文件。

在Rails中,如果你不告訴它重定向或渲染在控制器方法的最後一個特定的模板,它推斷出一個模板來渲染代替,因此:

class UsersController < ApplicationController 
    def create 
    @user = User.create(name: params[:name]) 
    end 
end 

如果create方法在這裏運行,用戶將被創建,然後Rails將嘗試渲染模板views/users/create.html.erb。通常情況下,你會不會有一個同名的模板 - 你可能會做這樣的事情:

class UsersController < ApplicationController 
    def create 
    @user = User.create(name: params[:name]) 
    redirect_to user_path(@user) 
    end 
end 

或者:

class UsersController < ApplicationController 
    def create 
    @user = User.create(name: params[:name]) 
    render :awesome_template 
end 

這一切都在這裏: http://guides.rubyonrails.org/v2.3.11/action_controller_overview.html#methods-and-actions

相關問題