Please solve such problem

36 views
Skip to first unread message

Paritosh P.

unread,
Nov 16, 2012, 3:17:20 AM11/16/12
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Nov 16, 2012, 3:41:22 AM11/16/12
to rubyonra...@googlegroups.com


On Friday, November 16, 2012 8:18:04 AM UTC, Ruby-Forum.com User wrote:
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

Paritosh P.

unread,
Nov 16, 2012, 3:48:08 AM11/16/12
to rubyonra...@googlegroups.com
> 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 .

Erwin

unread,
Nov 16, 2012, 9:48:08 AM11/16/12
to rubyonra...@googlegroups.com
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 ?

Paritosh P.

unread,
Nov 16, 2012, 10:09:19 AM11/16/12
to rubyonra...@googlegroups.com
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
.
.

Colin Law

unread,
Nov 16, 2012, 10:13:40 AM11/16/12
to rubyonra...@googlegroups.com
On 16 November 2012 15:09, Paritosh P. <li...@ruby-forum.com> wrote:
> 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

>
> 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
> .
> .
> .
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Paritosh P.

unread,
Nov 16, 2012, 10:25:56 AM11/16/12
to rubyonra...@googlegroups.com
Colin Law wrote in post #1084745:
> On 16 November 2012 15:09, Paritosh P. <li...@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 .

Colin Law

unread,
Nov 16, 2012, 10:38:40 AM11/16/12
to rubyonra...@googlegroups.com
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

Erwin

unread,
Nov 16, 2012, 11:15:23 AM11/16/12
to rubyonra...@googlegroups.com, cla...@googlemail.com
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...

Paritosh P.

unread,
Nov 16, 2012, 11:29:32 AM11/16/12
to rubyonra...@googlegroups.com
Colin Law wrote in post #1084753:
> On 16 November 2012 15:25, Paritosh P. <li...@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 .

Colin Law

unread,
Nov 16, 2012, 11:34:28 AM11/16/12
to rubyonra...@googlegroups.com
On 16 November 2012 16:29, Paritosh P. <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1084753:
>> On 16 November 2012 15:25, Paritosh P. <li...@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.

In that case I do not understand your needs.

Colin

Paritosh P.

unread,
Nov 16, 2012, 11:41:31 AM11/16/12
to rubyonra...@googlegroups.com
Colin Law wrote in post #1084776:
if so,Sorry if i wasted your time.

STOP

Colin Law

unread,
Nov 16, 2012, 11:50:59 AM11/16/12
to rubyonra...@googlegroups.com
Stop what?

Colin

Ace Suares

unread,
Nov 18, 2012, 6:16:40 AM11/18/12
to rubyonra...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages