我的rails应用说:
The action 'myjson' could not be found for UsersController
我整天都在阅读其他帖子,看起来这主要是由于缺少结局或其他原因造成的。但我真的不认为这是因为我真的试图查找它并找不到任何东西。所以我转向你寻求帮助。这是我的控制器代码:
class UsersController < ApplicationController
helper_method :sort_column, :sort_direction #method in helpers to sort
before_filter :signed_in_user, only: [:edit, :update, :destroy]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: [:destroy]
def index
@user = current_user
@usersall = User.all
@users =User.order(sort_column + " " + sort_direction).paginate(:per_page => 10, :page => params[:page])
@rank = User.select("users.name, sum(credits.score) AS rank").joins(:credits).group("credits.user_id").all
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_path
end
def create
if User.exists?(:email => params[:user][:email])
flash.now[:error] = "A user with this email already exists"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:password] != params[:user][:password_confirmation]
flash.now[:error] = "The passwords do not match. Try again"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:email] !~ /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
flash.now[:error] = "Invalid email"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:name] == nil
flash.now[:error] = "The name field cannot be empty"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:password].length < 6
flash.now[:error] = "Password is too short (minimal length: 6)"
render :action => :new, :layout => 'signin-layout.html.erb'
else
@user = User.new(params[:user])
@user.save
redirect_to @user
end
end
def show
@user = User.find(params[:id])
render :layout => 'user-layout.html.erb' #use a special layout
end
def edit
render :layout => 'user-layout.html.erb' #use a special layout
end
def update
if User.exists?(:email => params[:user][:email]) && params[:user][:email] != @user.email
flash.now[:error] = "A user with this email already exists"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:new_password] != params[:user][:password_confirmation]
flash.now[:error] = "The passwords do not match. Try again"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:email] !~ /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
flash.now[:error] = "Invalid email"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif params[:user][:name] == nil
flash.now[:error] = "The name field cannot be empty"
render :action => :new, :layout => 'signin-layout.html.erb'
elsif !@user.authenticate(params[:user][:password])
flash.now[:error] = "Entered password doesn't match with the one previously saved"
render :action => :new, :layout => 'signin-layout.html.erb'
else
@user.update_attribute(:name, params[:user][:name])
@user.update_attribute(:email, params[:user][:email])
if params[:user][:new_password] == params[:user][:password_confirmation] && params[:user][:new_password].length > 6
@user.update_attribute(:password, params[:user][:new_password])
end
sign_in @user
redirect_to @user
end
end
def upAdmin
@user = User.find(params[:id])
if @user.update_attribute(:admin,true)
flash[:success] = "Profile updated, welcome to the new admin"
redirect_to @user
else
flash[:error] = "Profile can't be upgraded to admin !'"
redirect_to @user
end
end
def downAdmin
@user = User.find(params[:id])
if @user.update_attribute(:admin,false)
flash[:success] = "Profile updated, bye to the old admin"
redirect_to @user
else
flash[:error] = "Profile can't be updated !'"
redirect_to @user
end
end
def myteam
@user = User.find(params[:id])
if @user.team_id != nil
@team = Team.find @user.team_id
end
render layout: 'user-layout.html.erb'
end
def myjson
render :layout => 'myjson.html.erb'
end
def myprojects
@user = User.find(params[:id])
render layout: 'user-layout.html.erb'
end
def mydevices
@user = User.find(params[:id])
render layout: 'user-layout.html.erb'
end
def mypins
@user = User.find(params[:id])
render layout: 'user-layout.html.erb'
end
private
def sort_column
User.column_names.include?(params[:sort]) ? params[:sort] : "name"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
end
def signed_in_user
redirect_to signin_path, notice: "Please sign in." unless signed_in?
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless (current_user?(@user) || current_user.admin?)
end
def admin_user
redirect_to(root_path) unless current_user.admin?
end
end
所以我希望我错过了它并没有什么严重的。以防万一这是我的routes.rb用户:
get "users/new"
resources :users do
member do
get 'myteam'
get 'myprojects'
get 'mydevices'
get 'mypins'
get 'upAdmin'
get 'downAdmin'
get 'myjson'
end
end
感谢您提前提供任何帮助