scaffold
を使い作成されたviewに加えてもう1つviewを作りたいのですが下記のエラー画面になってしまい追加したリンク(/users/company)にアクセスできません。rake routes
にてリンクが作成できているのは確認済みです。
分かる方いましたらよろしくお願いします。
Rails ver は5.0.7.2です。
親:User テーブル (company,userid,pass,memo)
子:Schedule テーブル (time,user_id,category_id)
Category テーブル (category)
ruby
1# $ rake route 2 Prefix Verb URI Pattern Controller#Action 3 users GET /users(.:format) users#index 4 POST /users(.:format) users#create 5 new_user GET /users/new(.:format) users#new 6 edit_user GET /users/:id/edit(.:format) users#edit 7 user GET /users/:id(.:format) users#show 8 PATCH /users/:id(.:format) users#update 9 PUT /users/:id(.:format) users#update 10 DELETE /users/:id(.:format) users#destroy 11users_company GET /users/company(.:format) users#company
ruby
1#users_controller 2 3 4 5# GET /users/company 6 def company 7 8 end 9 10 11 # GET /users 12 # GET /users.json 13 def index 14 @users=User.all 15 @categories=Category.all 16 end 17 18 # GET /users/1 19 # GET /users/1.json 20 def show 21 end 22 23 # GET /users/new 24 def new 25 @user = User.new 26 @schedule = @user.schedules.build 27 @categories=Category.all 28 end 29 30 # GET /users/1/edit 31 def edit 32 @categories=Category.all 33 end 34 35 # POST /users 36 # POST /users.json 37 def create 38 @user = User.new(user_params) 39 40 redirect_to "/users" 41 end 42 43 44 45 # PATCH/PUT /users/1 46 # PATCH/PUT /users/1.json 47 def update 48 respond_to do |format| 49 if @user.update(user_params) 50 format.html { redirect_to @user, notice: 'User was successfully updated.' } 51 format.json { render :show, status: :ok, location: @user } 52 else 53 format.html { render :edit } 54 format.json { render json: @user.errors, status: :unprocessable_entity } 55 end 56 end 57 end 58 59 # DELETE /users/1 60 # DELETE /users/1.json 61 def destroy 62 @user.destroy 63 respond_to do |format| 64 format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } 65 format.json { head :no_content } 66 end 67 end 68 69 private 70 # Use callbacks to share common setup or constraints between actions. 71 def set_user 72 @user = User.find(params[:id]) 73 end 74 75 # Only allow a list of trusted parameters through. 76 def user_params 77 params.require(:user).permit(:company, :userid, :pass, :memo,schedules_attributes: [:id, :time, :user_id, :category_id,:_destroy ] ) 78 end 79end 80
ruby
1#route.rb 2Rails.application.routes.draw do 3 resources :users 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5 get "/users/company", to:"users#company" 6 7end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/18 03:10