ruby on rails - No route matches {:action=>"show", :controller=>"scoo.....missing required keys: [:id] -


i have partial form create , update...for new render partial when going edit 1 keep getting error

actioncontroller::urlgenerationerror in scoopes#edit no route matches {:action=>"show", :controller=>"scoopes", :id=>nil, :user_name=>#<scoope id: 11, name: "asdsada", user_id: 3, created_at: "2016-08-07 20:37:52", updated_at: "2016-08-07 20:37:52">} missing required keys: [:id] 

i search answer old questions no 1 solved problem...the form creating scoopes....

the assosiaction between scoope , users :

scoope belong_to user , user has_many scoopes 

here scoope controller:

class scoopescontroller < applicationcontroller   before_action :authenticate_user!, except: [:show]   before_action :set_scoope, only: [:show, :edit, :update, :destroy, :index]   before_action :owned_scoope, only: [:edit, :update, :destroy]    def index     @scoopes = @user.scoopes.all   end    def show     @scoope = @user.scoopes.find(params[:id])   end    def new     @scoope = current_user.scoopes.build   end    def create     @scoope = current_user.scoopes.build(scoope_params)     if @scoope.save         redirect_to scoope_path(current_user.user_name, @scoope)     else         render 'new'     end   end    def edit     @scoope = @user.scoopes.find(params[:id])   end    def update     @scoope = @user.scoopes.find(params[:id])     if @scoope.update(scoope_params)         redirect_to scoope_path(@user, @scoope)     else         render 'edit'     end   end     def destroy     @scoope = @user.scoopes.find(params[:id])     @scoope.destroy     redirect_to scoopes_path   end    private    def scoope_params     params.require(:scoope).permit(:name)   end    def set_scoope     @user = user.find_by(user_name: params[:user_name])   end   def owned_scoope     unless @user == current_user         flash[:danger] = "this scope dont belong you"         redirect_to root_path     end   end end 

here partial form(i think maybe problem somehow related edit path because when try yo replace scoope edit_scoope_path render form under edit page..but not solve whale problem because partial):

<div class="row">   <div class="col-md-5 formm">     <%= render 'shared/errors', obj: @scoope %>     <div class="well">       <%= form_for @scoope |f| %>         <div class="form-group">           <%= f.label :name %><br/>           <%= f.text_area :name, rows: 6, class: 'form-control' %>         </div>         <div class="form-group">           <%= f.submit class: 'btn btn-primary'  %> <%= link_to "back", :back, class: "btn btn-danger" unless current_page?(scoopes_path) %>         </div>       <% end %>     </div>   </div> </div> 

here routes scoopes:

               scoopes    /:user_name/scoopes(.:format)               scoopes#index                      post   /:user_name/scoopes(.:format)               scoopes#create           new_scoope    /:user_name/scoopes/new(.:format)           scoopes#new          edit_scoope    /:user_name/scoopes/:id/edit(.:format)      scoopes#edit               scoope    /:user_name/scoopes/:id(.:format)           scoopes#show                      patch  /:user_name/scoopes/:id(.:format)           scoopes#update                      put    /:user_name/scoopes/:id(.:format)           scoopes#update                      delete /:user_name/scoopes/:id(.:format)           scoopes#destroy 

my scoope table:

create_table "scoopes", force: :cascade |t|   t.string   "name"   t.integer  "user_id"   t.datetime "created_at", null: false   t.datetime "updated_at", null: false end 

routes:

devise_for :users, :controllers => { :registrations => "user/registrations" } root "posts#index"  scope '/:user_name'  resources :scoopes end ':user_name', to: 'profiles#show', as: :profile   ':user_name/edit', to: 'profiles#edit', as: :edit_profile   patch ':user_name/edit', to: 'profiles#update', as: :update_profile   ................ 

problem lies routes.rb file. can add nested routes below:

resources :users   resources :scoopes end  

that output urls below.from output can see path user_scoope_path(current_user, @scoope) .

                                                                                                                                             scoopes#index                                                             post     /users/:user_id/scoopes(.:format)                                          scoopes#create                                             new_user_scoope      /users/:user_id/scoopes/new(.:format)                                      scoopes#new                                            edit_user_scoope      /users/:user_id/scoopes/:id/edit(.:format)                                 scoopes#edit                                                 user_scoope      /users/:user_id/scoopes/:id(.:format)                                      scoopes#show                                                             patch    /users/:user_id/scoopes/:id(.:format)                                      scoopes#update                                                             put      /users/:user_id/scoopes/:id(.:format)                                      scoopes#update                                                             delete   /users/:user_id/scoopes/:id(.:format)                                      scoopes#destroy 

hope helps.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -