Forum: Ruby on Rails Please solve such problem

Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 09:17
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2012-11-16 09:42
(Received via mailing list)
On Friday, November 16, 2012 8:18:04 AM UTC, Ruby-Forum.com User wrote:
>
> 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

Currently i thought to use scope method in config/route.rb or i will
Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 09:48
> 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 .
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2012-11-16 15:49
(Received via mailing list)
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
:
Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 16:09
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
.
.
.
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-11-16 16:15
(Received via mailing list)
On 16 November 2012 15:09, Paritosh P. <lists@ruby-forum.com> wrote:
>> 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
Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 16:25
Colin Law wrote in post #1084745:
> On 16 November 2012 15:09, Paritosh P. <lists@ruby-forum.com> wrote:
>>> 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 .
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-11-16 16:40
(Received via mailing list)
On 16 November 2012 15:25, Paritosh P. <lists@ruby-forum.com> wrote:
>> 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
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2012-11-16 17:16
(Received via mailing list)
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 :
Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 17:29
Colin Law wrote in post #1084753:
> On 16 November 2012 15:25, Paritosh P. <lists@ruby-forum.com> wrote:
>>> 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 .
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-11-16 17:36
(Received via mailing list)
On 16 November 2012 16:29, Paritosh P. <lists@ruby-forum.com> wrote:
>>>> 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.

In that case I do not understand your needs.

Colin
Bcb2185dd24051bce727b29230a2c171?d=identicon&s=25 Paritosh P. (paritosh_p)
on 2012-11-16 17:41
Colin Law wrote in post #1084776:
> On 16 November 2012 16:29, Paritosh P. <lists@ruby-forum.com> wrote:
>>>>> 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.
>
> In that case I do not understand your needs.
>
> Colin

if so,Sorry if i wasted your time.

STOP
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-11-16 17:52
(Received via mailing list)
On 16 November 2012 16:41, Paritosh P. <lists@ruby-forum.com> wrote:
>>>> Colin
>>>
>>> i didn't said anything for his suggestion . but doesn't fit my needs.
>>
>> In that case I do not understand your needs.
>>
>> Colin
>
> if so,Sorry if i wasted your time.
>
> STOP

Stop what?

Colin
Fef890509958b45df342b53e839920c9?d=identicon&s=25 Ace S. (ace_s)
on 2012-11-18 12:18
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.