Please solve such problem

Hi, I unable to follow DRY principle. I struck in situation where actions are same but controller are different.Wait,let me explain you with example .

http://www.example.com/en/xyz/abc http://www.example.com/en/mnb/abc http://www.example.com/en/xkj/abc http://www.example.com/en/cbc/abc

As you see in above URLs second last parameter is changing every time . How to tackle such situation.

Currently i thought to use scope method in config/route.rb or i will create separate controller for each /xyz/ , /mnb/ , /xkj/ .

How do you solve such problem ? It will be good if you tell me way which follow DRY and flexible too.

Thanks.

Hi,

I unable to follow DRY principle. I struck in situation where actions

are same but controller are different.Wait,let me explain you with

example .

http://www.example.com/en/xyz/abc

http://www.example.com/en/mnb/abc

http://www.example.com/en/xkj/abc

http://www.example.com/en/cbc/abc

As you see in above URLs second last parameter is changing every time .

How to tackle such situation.

It’s hard to say when I don’t knwo what you’re doing in those controllers but if they’re the same and it’s just the routing you’re asking about you could have a route such as

match ‘/en/:param1/abc’, :to => ‘foo#index’

which would route all those urls to the index action of your foo controller, setting params[:param1] appropriately

Fred

It's hard to say when I don't knwo what you're doing in those controllers

Contents are different for all whose urls,but having same layout .

if generated content is different

match ‘/en/:param1/abc’, :to => ‘foo#param1’

and you will have different actions #xyz , #mnb , #xkj, #cbc in your foo controller

with same layout

can you clarify using samples urls ?

Kad Kerforn wrote in post #1084737:

if generated content is different

match '/en/:param1/abc', :to => 'foo#param1'

and you will have different actions #xyz , #mnb , #xkj, #cbc in your foo controller with same layout

can you clarify using samples urls ?

Le vendredi 16 novembre 2012 09:48:45 UTC+1, Ruby-Forum.com User a crit :

sample urls . http://0.0.0.0:3000/fr/School_1/index http://0.0.0.0:3000/fr/School_1/about_us http://0.0.0.0:3000/fr/School_1/admission

http://0.0.0.0:3000/fr/School_2/index http://0.0.0.0:3000/fr/School_2/about_us http://0.0.0.0:3000/fr/School_2/admission

http://0.0.0.0:3000/fr/School_3/index http://0.0.0.0:3000/fr/School_3/about_us http://0.0.0.0:3000/fr/School_3/admission

http://0.0.0.0:3000/fr/School_4/index http://0.0.0.0:3000/fr/School_4/about_us http://0.0.0.0:3000/fr/School_4/admission

It shares same layout means

class School_1Controller < ApplicationController     layout "shared_layout.html.erb" end

class School_2Controller < ApplicationController    layout "shared_layout.html.erb" end . . .

Kad Kerforn wrote in post #1084737:

if generated content is different

match '/en/:param1/abc', :to => 'foo#param1'

and you will have different actions #xyz , #mnb , #xkj, #cbc in your foo controller with same layout

can you clarify using samples urls ?

Le vendredi 16 novembre 2012 09:48:45 UTC+1, Ruby-Forum.com User a crit :

sample urls . http://0.0.0.0:3000/fr/School_1/index http://0.0.0.0:3000/fr/School_1/about_us http://0.0.0.0:3000/fr/School_1/admission

http://0.0.0.0:3000/fr/School_2/index http://0.0.0.0:3000/fr/School_2/about_us http://0.0.0.0:3000/fr/School_2/admission

Are school_1 and school_2 different models? If so, why? I see they different controllers? Why?

Colin

Colin Law wrote in post #1084745:

can you clarify using samples urls ?

http://0.0.0.0:3000/fr/School_2/index http://0.0.0.0:3000/fr/School_2/about_us http://0.0.0.0:3000/fr/School_2/admission

Are school_1 and school_2 different models? If so, why? I see they different controllers? Why?

Colin

i didn't used model yet . As you see,above the site is partially static , so i just been focused on views/ . This is what my problem is and it is what i want to know. How did you tackle such situation ?

I see they different controllers? Why?

if you have some idea , tell me .

What is wrong with the suggestion offered by Fred, which allows you send them to the same controller but with params indicating which school it is?

Colin

if all pages are static , isn’t better to use a gem like HighVoltage ?

it’s what I have been using when no need for CMS…

Colin Law wrote in post #1084753:

Colin

i didn't used model yet . As you see,above the site is partially static , so i just been focused on views/ . This is what my problem is and it is what i want to know. How did you tackle such situation ?

I see they different controllers? Why?

if you have some idea , tell me .

What is wrong with the suggestion offered by Fred, which allows you send them to the same controller but with params indicating which school it is?

Colin

i didn't said anything for his suggestion . but doesn't fit my needs.

if all pages are static , isn't better to use a gem like HighVoltage ? it's what I have been using when no need for CMS...

Le vendredi 16 novembre 2012 16:39:51 UTC+1, Colin Law a crit :

logic behind HighVoltage is not big.I rather construct with scratch as per my needs.Moreover my pages are not fully static also.Anyway thanks for your suggestion .

In that case I do not understand your needs.

Colin

Colin Law wrote in post #1084776:

Stop what?

Colin

The suggestion posted by fred is really well suited for your need.

for instance, if you go to 0.0.0.0:3000/fr/School1/abc

this will be routed to the #abc controller, but with param1=‘School1’

def abc @School=School.find_by_name(:param1) @content=@school.pages.find_by_name(action_name) end

Now in your layout, you will have available @School, which has all the information about the school, and @content, which contains the content of the page ‘about us’ etc etc.

If your content is static, this is not a good solution.

Au revoir,

Ace