Raffles rails problem # undefined method `edit_pais_path '

I created a sketch called pais (this word is in Portuguese in Brazil and is the same as in the country), I created using the following command:

ruby script\generate scaffold pais name:string abreviattion:string 

First I changed the kinks to my local idiom, for example:

 inflect.plural /^([a-zA-z]*)s$/i, '\1ses' #The plural of Pais is Paises 

And when I tried to open the page at http: // localhost: 3000 / paises , I get the following error:

 undefined method `edit_pais_path' for #<ActionView::Base:0x387fdf4> 

Thanks in advance.

+4
source share
2 answers

Problem

"pais".pluralize results in "pais"

This is really common for people who decide to create a News model. Rails should distinguish between a single and multiple version of your model.

routes.rb

 map.resources :pais, :singular => :pai 

Now you will use

pai_path , edit_pai_path and new_pai_path


As an alternative

 map.resources :pais, :as => "goats" 

Will generate these paths for you:

 HTTP URL controller action GET /goats Pais index GET /goats/new Pais new POST /goats Pais create GET /goats/1 Pais show GET /goats/1/edit Pais edit PUT /goats/1 Pais update DELETE /goats/1 Pais destroy 

Checkout Rails Routing from the Outside in Guide to guides.rubyonrails.org for more information.

+3
source

I worked a bit with this, and I found a solution that might help you a little better.

Step 1

BEFORE you create your scaffold, make sure your inflections.rb file has the correct bend.

 ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'pokem', 'pokemon' end 

Step 2

Now you can create your scaffold

 [bruno ~/pokedex]$ script/generate scaffold pokem name:string 

Step 3

Check out our great new routes!

 [bruno ~/pokedex]$ rake routes pokemon GET /pokemon(.:format) {:controller=>"pokemon", :action=>"index"} POST /pokemon(.:format) {:controller=>"pokemon", :action=>"create"} new_pokem GET /pokemon/new(.:format) {:controller=>"pokemon", :action=>"new"} edit_pokem GET /pokemon/:id/edit(.:format) {:controller=>"pokemon", :action=>"edit"} pokem GET /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"show"} PUT /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"update"} DELETE /pokemon/:id(.:format) {:controller=>"pokemon", :action=>"destroy"} 

Note

If you create your scaffold before , you define your inflection, named routes will not be updated.

+1
source

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


All Articles