用户和注册模型(每个用户都有一个注册表) - 在我的Rails应用程序有设备型号是。
我想改变我的路线,这样,而不是:
的 “http://本地主机:3000 /注册/ 3”
表明:
“HTTP://本地主机:3000 / erinwalker”
所以我改变路线
match '/:name' => "registries#show"
而在我的控制器中的表演动作:
def show
@user = current_user
@user = User.find_by_name!(params[:name])
@registry = @user.registry
和它的作品,但是当我创建或现在先更新注册表,它说:
Couldn't find User with name =
app/controllers/registries_controller.rb:21:in `show'
尽管演出行动工作?
所述注册控制器:类RegistriesController <ApplicationController中的before_filter:的authenticate_user!:除了=>:显示load_and_authorize_resource
# GET /registries
# GET /registries.json
def index
@registries = Registry.all
@user = current_user
respond_to do |format|
format.html # index.html.erb
format.json { render json: @registries }
end
end
# GET /registries/1
# GET /registries/1.json
def show
@user = current_user
@user = User.find_by_name!(params[:name])
@registry = @user.registry
respond_to do |format|
format.html # show.html.erb
format.json { render json: @registry }
end
end
# GET /registries/new
# GET /registries/new.json
def new
@registry = Registry.new
@user = current_user
respond_to do |format|
format.html # new.html.erb
format.json { render json: @registry }
end
end
# GET /registries/1/edit
def edit
@registry = Registry.find(params[:id])
@user = current_user
end
# POST /registries
# POST /registries.json
def create
@registry = current_user.build_registry(params[:registry])
@user = current_user
respond_to do |format|
if @registry.save
format.html { redirect_to @registry, notice: 'Registry was successfully created.' }
format.json { render json: @registry, status: :created, location: @registry }
else
format.html { render action: "new" }
format.json { render json: @registry.errors, status: :unprocessable_entity }
end
end
end
# PUT /registries/1
# PUT /registries/1.json
def update
@registry = Registry.find(params[:id])
@user = current_user
respond_to do |format|
if @registry.update_attributes(params[:registry])
format.html { redirect_to @registry, notice: 'Registry was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @registry.errors, status: :unprocessable_entity }
end
end
end
我的所有路由:
Mystorkparty::Application.routes.draw do
devise_for :users
resources :registries
root :to => "static_pages#home"
match '/home', to: 'static_pages#home'
match '/:name' => "registries#show"