Could not find <object> without ID rails 3.0.1

Unfortunately, this is my second post in so many days. Thus, the application worked fine with mysql and rails 3.0.3, but I found out that I needed to use MSSQL, so I had to lower the rails to 3.0.1.

In a nutshell, I copied show.html.erb as show2.html.erb and created a new method, which is a copy of the show method. Then I created a route.

my controller

class fathersController < ApplicationController
  def show
    @father= Father.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @father}
    end
  end

  def show2
    @father= Father.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @father}
    end
  end
end

routes.rb

resources :fathers do
    match '/show2' => 'fathers#show2'
    resources :kids
end

when i call

http://127.0.0.1:3000/father/1

I get a view of the view, but when I call

http://127.0.0.1:3000/father/1/show2

I get the following error

Couldn't find father without an ID

Request parameters are returned as

{"father_id"=>"1"}

so I know that the problem is that the application passes id as father_id, but how to fix it? Any help would be appreciated.

+3
1

.

  • , .
  • , /show2 hospitals, fathers.

:

resources :fathers do
  get :show2, :on => :member
  resources :kids
end

:

resources :fathers do
  member do
    get :show2
  end

  resources :kids
end    
+1

Source: https://habr.com/ru/post/1784210/


All Articles