Rails模板丢失了

时间:2014-05-22 23:39:52

标签: ruby-on-rails ruby twitter-bootstrap

嗨,有谁知道导致此错误的原因。

我是rails的新手,但我猜它与bootstrap有关。但是,我不知道如何修复它并且我已经尝试了最近2个小时。

  

错误

Template is missing
Missing template authentication/account_settings, application/account_settings with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/action/workspace/PAW/app/views" * "/home/action/.rvm/gems/ruby-2.1.1/gems/twitter-bootstrap-rails-2.2.8/app/views"

我在身份验证控制器中定义了account_settings

  

authentication_controller.rb

# Class written by Alan Dunne after following tutorials by Marc Clifton [Available @ http://www.codeproject.com/Articles/575551/User-Authentication-in-Ruby-on-Rails#AdministratingUsers78]
class AuthenticationController < ApplicationController
  def sign_in
    @user = User.new
  end

  def login
    username_or_email = params[:user][:username]
    password = params[:user][:password]

    if username_or_email.rindex('@')
      email=username_or_email
      user = User.authenticate_by_email(email, password)
    else
      username=username_or_email
      user = User.authenticate_by_username(username, password)
    end

    if user
      session[:user_id] = user.id
      flash[:notice] = 'Welcome' 
      redirect_to '/home'
    else
      flash.now[:error] = 'Unknown user. Please check your username and password.'

      # Assign user to instance variable for the `sign_in` view!
      @user = User.new(params[:user]) 

      render :action => "sign_in"
    end
  end

  def signed_out
    session[:user_id] = nil
    flash[:notice] = "You have been signed out."
  end

  def new_user
    @user = User.new
  end

  def register
    @user = User.new(params[:user])

    if @user.valid?
      @user.save
      session[:user_id] = @user.id
      flash[:notice] = 'Welcome.'
      redirect_to :root
    else
      render :action => "new_user"
    end
  end  

  def account_settings
    @user = current_user
  end

  def set_account_info
    old_user = current_user

    # verify the current password by creating a new user record.
    @user = User.authenticate_by_username(old_user.username, params[:user][:password])

    # verify
    if @user.nil?
      @user = current_user
      @user.errors[:password] = "Password is incorrect"
      render :action => "account_settings"
    else
      # update the user with any new username and email
      @user.update(params[:user])
      # Set the old email and username, which is validated only if it has changed.
      @user.previous_email = old_user.email
      @user.previous_username = old_user.username

      if @user.valid?
    # If there is a new_password value, then we need to update the password.
    @user.password = @user.new_password unless @user.new_password.nil? || @user.new_password.empty?
    @user.save
    flash[:notice] = 'Account settings have been changed'
    redirect_to :root
      else
    render :action => "account_settings"
      end
    end
  end

end
  

的routes.rb

Rails.application.routes.draw do
  resources :match_picks

  resources :matches

  root :to=>"home#index"
  get "sign_in" => "authentication#sign_in"
  # get "home" => "authentication#login"  
  # get "instructions" => 'home'
  get "signed_out" => "authentication#signed_out"
  get "new_user" => "authentication#new_user"
  post "sign_in" => "authentication#login"
  put "sign_in" => "authentication#login"
  post "new_user" => "authentication#register"
  put "new_user" => "authentication#register"
  get "admin_users" => "admin#users"
  delete "user/:id" => "admin#delete_user", :as => "user"
  get "admin_users" => "authentication#admin_users"
  get '/home', to: 'home#home'
  get '/instructions', to: 'home#instructions'
  get '/blocks', to: 'home#blocks'  
  post "match/create-match-pick" => "matches#create_match_pick", :as => :create_match_pick
  get "account_settings" => "authentication#account_settings"
  put "account_settings" => "authentication#set_account_info"

  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  # root 'welcome#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

3 个答案:

答案 0 :(得分:2)

控制器方法:

  def account_settings
    @user = current_user
  end

希望呈现位于以下位置的模板文件:

views / authentication / account_settings.html.erb(或.jbuilder等)

该文件是否存在?如果没有,你应该创建它。

答案 1 :(得分:1)

您错过了一个视图。

应该是这个文件:/app/views/authentication/account_settings.html.erb

答案 2 :(得分:1)

您的错误表明您期待名为account_settings.html.erb

的文件

转到:app/views/authentication/,然后搜索该文件。