Changing the default view path for a controller...

0 views
Skip to first unread message

bmcc

unread,
Dec 8, 2009, 11:27:39 AM12/8/09
to Orlando Ruby Users Group Discussion
Ok here is the scenerio. I have 2 classes and a module.

module UserHelper

#the views for these actions are in /apps/view/user

def favorites

end

def friends

end

end

class UserController < ApplicationController

include UserHelper

end

#a developer is a user with added functionality
class DeveloperController < ApplicationController

include UserHelper

def profile

end

def upload

end

end


Now this is working except when I go to this URL: /developer/favorites
there is a problem. It is looking for a view that is in the /apps/
views/user folder. I can throw redirects into each action in
UserHelper but that does not seem right. Especailly when the
UserHelper actions are being used in User, I would be redirecting to
the same controller that I am already in. I need to let the developer
controller know that it needs to look in the /apps/views/user for the
actions in the UserHelper module but look in its own views for the two
methods that originate in the Developer Controller. Actually Can I
force all the actions in the UserHelper to use the /apps/views/user
path regardless of where the module is being included at without using
redirects, and without effecting the other action in the class
including the module?

Some help please. I have read up ona few functions like:
append_view_path and view_paths= but they are not clear to me maybe
someone can clear things up for me.

Thanks

-Barry

caike

unread,
Dec 8, 2009, 11:48:35 AM12/8/09
to orug-di...@googlegroups.com
Have you looked at render :template => "path/to/view".

I have never used it so I don't know how it handles layouts.


--

You received this message because you are subscribed to the Google Groups "Orlando Ruby Users Group Discussion" group.
To post to this group, send email to orug-di...@googlegroups.com.
To unsubscribe from this group, send email to orug-discussi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/orug-discussion?hl=en.





--
Att,
- Caike
http://caikesouza.com

bmcc

unread,
Dec 9, 2009, 6:00:36 PM12/9/09
to Orlando Ruby Users Group Discussion
It looks like it just changes what layout is rendered not the app/
views/"path".
> > orug-discussi...@googlegroups.com<orug-discussion%2Bunsubscribe@­googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/orug-discussion?hl=en.
>
> --
> Att,
> - Caikehttp://caikesouza.com- Hide quoted text -
>
> - Show quoted text -

bmcc

unread,
Dec 10, 2009, 12:51:40 AM12/10/09
to Orlando Ruby Users Group Discussion
Well I messed around with it and it works so problem solved. Thanks
caike.
> > - Caikehttp://caikesouza.com-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

Rodney Degracia

unread,
Dec 10, 2009, 10:01:20 AM12/10/09
to orug-di...@googlegroups.com
What is the solution!?


R
> To unsubscribe from this group, send email to orug-discussi...@googlegroups.com.

bmcc

unread,
Dec 16, 2009, 10:28:22 AM12/16/09
to Orlando Ruby Users Group Discussion
Sorry for not putting up the solution earlier, here is what I have
come to.

At first I had a module that I was trying to fake multiple inheritance
through.

module UserHelper

#the views for these actions are in /apps/view/user
def favorites

render :template => "/user/favorites" #<--added these after
first post
end

def friends

render :template => "/user/friends" #<--added these after
first post
end
end

class UserController < ApplicationController


include UserHelper

end


#a developer is a user with added functionality
class DeveloperController < ApplicationController

include UserHelper

def profile

#template is in views/developer
end

def upload

#template is in views/developer
end
end

With this setup i can do this: localhost:300/developer/friends and get
a view to render that was in the user's view. I experimented with this
for a while then I talked to a more experienced rails programmer. He
said to take the actions out of the userhelper module and put them
where they belong (the user controller); then do what I was trying to
do through routes. If I needed to determine if a user was a developer
before I perform an action to use a before_filter in the user
controller. So this is the code that I put into my routes.

map.connect "developer/:action",
:requirements => {:action => /profile|upload/ },
:controller => "developer"

map.connect "developer/:action",
:controller => "user"

I felt that this was more concise and allowed for the proper code to
be in its respected controller. The problem I see with this is
everytime that I add an action to the developers section I have to g
oback to my routes file and add it to the regular expression.

So I was wondering if there was a way I could make these routes
dynamic enough to look into the developer controller if it cant find
the action in the user controller?


Once again Thank.

-Barry
> >> > - Caikehttp://caikesouza.com-Hidequoted text -
>
> >> > - Show quoted text -- Hide quoted text -
>
> >> - Show quoted text -
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "Orlando Ruby Users Group Discussion" group.
> > To post to this group, send email to orug-di...@googlegroups.com.
> > To unsubscribe from this group, send email to orug-discussi...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/orug-discussion?hl=en.- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages