Relationship question has_many

the belongs_to and has_many is ok so far.

but it is a VERY bad idea to use dutch naming, since it breaks the pluralization rules of Rails and forces you to use a lot of explicit declarations.

(tells you a german programmer living/working in Amsterdam, we NEVER do this and my dutch colleagues are surely as proud of their language as you may be :slight_smile:

class Countries < ActiveRecord::Base   belongs_to :continent end

class Continents < ActiveRecord::Base   has_many :countries end

would be all you need, if you would keep to standards and this will go on with all you routing, path_helpers and whatsoever...

Thorsten Mueller wrote:

the belongs_to and has_many is ok so far.

but it is a VERY bad idea to use dutch naming, since it breaks the pluralization rules of Rails and forces you to use a lot of explicit declarations.

(tells you a german programmer living/working in Amsterdam, we NEVER do this and my dutch colleagues are surely as proud of their language as you may be :slight_smile:

class Countries < ActiveRecord::Base   belongs_to :continent end

class Continents < ActiveRecord::Base   has_many :countries end

would be all you need, if you would keep to standards and this will go on with all you routing, path_helpers and whatsoever...

I agree it is a bad idea to generate controllers/model ect. in my own language. But i want to make my url-structure in my own language in case of SEO. Do you have some url's to solve this problem.

remco

Thorsten Mueller wrote:

class Countries < ActiveRecord::Base class Continents < ActiveRecord::Base

Surely: class Country < ActiveRecord::Base class Continent < ActiveRecord::Base ?

In answer to the original question 2, use nested routes (in config/routes.rb):

map.resources :continents do |continent|   continent.resources :countries end

or a sub-resource:

map.resources :continents, :has_many => :countries

They will generate the same routes. If you will want to access countries independently then make sure it has its own resource:

map.resources :countries

Use: rake routes to check your routing is what you want it to be.

Remco Zwaan wrote:

But i want to make my url-structure in my own language in case of SEO. Do you have some url's to solve this problem.

Use the routes.rb file to create routes that match your required pattern and map to appropriate actions...

Remco Zwaan wrote:

<li><%= link_to land.naam, land_path(land)%></li>

But i get the error message: undefined method `land_path' for #<ActionView::Base:0xb75eaf30

This will be related to the internal pluralisation and singularisation used by Rails (which is why sticking to English words works best). Still, you can sort this out using the command:

rake routes

This will include a line with a URL matching what you need. There should be a method name stub to the left. Add "_path" to that.

Also, you can use Rails magic and use:

link_to land.naam, land

Rails will recognise the object and should generate the correct URL. Of course, the non-English words and irregular pluralisation of your table name may fox Rails here, too.

Another approach is to teach Rails how to pluralise your model names. Add inflection entries to your environment.rb file to teach Rails the relation land<->landen.

Mark Bush wrote:

Remco Zwaan wrote:

<li><%= link_to land.naam, land_path(land)%></li>

But i get the error message: undefined method `land_path' for #<ActionView::Base:0xb75eaf30

This will be related to the internal pluralisation and singularisation used by Rails (which is why sticking to English words works best). Still, you can sort this out using the command:

rake routes

This will include a line with a URL matching what you need. There should be a method name stub to the left. Add "_path" to that.

Also, you can use Rails magic and use:

link_to land.naam, land

Rails will recognise the object and should generate the correct URL. Of course, the non-English words and irregular pluralisation of your table name may fox Rails here, too.

Another approach is to teach Rails how to pluralise your model names. Add inflection entries to your environment.rb file to teach Rails the relation land<->landen.

Hi..

rake routes werelddeel_landen GET /werelddeel/:werelddeel_id/landen/:id

So i put werelddeel_landen in the path:

<% @landen.each do |land| %> <li><%= link_to land.naam, werelddeel_landen_path(land)%></li> <% end %>

On http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika

Link Afghanistan i get: http://www.goedkoop-vliegen.nu/werelddeel/afghanistan/landen/noord-amerika

something wrong here!! grgrgrgr

models:

class Land < ActiveRecord::Base   belongs_to :werelddeel, :foreign_key => "werelddeel_id"    set_table_name "landen"    set_primary_key "landcode"

  has_permalink :land_zoeknaam

  def to_param    land_zoeknaam   end end

class Werelddeel < ActiveRecord::Base   has_many :land, :foreign_key => "werelddeel_id"   set_table_name "werelddelen"   set_primary_key "werelddeel_id"   has_permalink :zoeknaam

  def to_param    zoeknaam   end

end

I case of nice url's (has_permalink, to_param) i use http://svn.techno-weenie.net/projects/plugins/permalink_fu/

i am getting a headache of this problem :frowning:

Grtz..remco

Remco Zwaan wrote:

werelddeel_landen GET /werelddeel/:werelddeel_id/landen/:id

<li><%= link_to land.naam, werelddeel_landen_path(land)%></li> <% end %>

On http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika

Link Afghanistan i get: http://www.goedkoop-vliegen.nu/werelddeel/afghanistan/landen/noord-amerika

You are supplying the :id field (in "land") to werelddeel_landen, but you also need to supply a value for :wereldeel_id. I think you can do this using:

link_to land.naam, werelddeel_landen_path(land.werelddeel, land)

Mark Bush wrote:

Remco Zwaan wrote:

werelddeel_landen GET /werelddeel/:werelddeel_id/landen/:id

<li><%= link_to land.naam, werelddeel_landen_path(land)%></li> <% end %>

On http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika

Link Afghanistan i get: http://www.goedkoop-vliegen.nu/werelddeel/afghanistan/landen/noord-amerika

You are supplying the :id field (in "land") to werelddeel_landen, but you also need to supply a value for :wereldeel_id. I think you can do this using:

link_to land.naam, werelddeel_landen_path(land.werelddeel, land)

Hee..Bush

It works!!!!....thanks...!!!

check the result > http://www.goedkoop-vliegen.nu/werelddeel

last question :slight_smile:

There is a belongs_to relationship between werelddeel (continents) and landen (countries). So how can i create a view on the continent Europe that only the countries belongs to Europe are visible.

Grtz....