ruby-on-rails - 缺少 Rails 模板

标签 ruby-on-rails ruby twitter-bootstrap

您好,有谁知道是什么导致了这个错误。

我是 Rails 的新手,但我猜它与 Bootstrap 有关。但是,我不知道如何修复它,过去 2 小时我一直在尝试。

Error

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"

我在身份验证 Controller 中定义了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

最佳答案

Controller 方法:

  def account_settings
    @user = current_user
  end

正在寻找呈现位于以下位置的模板文件:

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

那个文件存在吗?如果没有,您应该创建它。

关于ruby-on-rails - 缺少 Rails 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23818818/

相关文章:

javascript - 如何自动安装丢失的yarn包?

ruby-on-rails - 从 Ruby 控制台创建一个设计用户

Ruby 和 Redis,线程不处理命令

css - 如何使用 SASS 覆盖 Bootstraps "btn-primary"事件背景颜色?

twitter-bootstrap - 使用平衡的 CSS flex-wrap 容器进行导航

ruby-on-rails - 确定具有特定风格的图像存在与否 - 回形针 rails

ruby-on-rails - 在Rails应用中进行长轮询

ruby-on-rails - 如何针对不同的验证错误显示不同的错误消息?

ruby - 使用 ruby​​ 规范化数据集

jquery - Bootstrap-select 无法正确显示最后一个选项元素