Hello, I am relatively new to RoR and I am trying to implement a simple content management system. I know I am reinventing the wheel but you don''t learn much using someone else''s code. So anyway, my website has a main controller. I use a layout "main" shared by all the controllers on the website (using the layout ''main'' declaration in the controllers). In the layout, I use an application_helper to display informations related to the user (if he has messages, logged or not, etc..) which selects the right partials to render (if not logged in -> display the log in form, if logged -> display user infos) The problem : RoR is looking for the partial files in the view directory of the currently used controller. It''s fine as long as I am using the main controller. But if for exemple the users wants to modify its profile (which is hadnled by the user controller), there''s an error stating that partials cannot be found in the controller views. Is it a design flaw on my part or is there a way to have partials availaible for all controllers so I can use them in a single layout for my whole application ? Thanks in advance ! Nicolas Jaccard -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
You can include the path to your partial when you render it: render :partial => ''user/my_partial1'' render :partial => ''comment/my_partial2'' As for the way you''ve describe your app, it sounds like you''re triggering a lot of queries from your helpers. Personaly I like to keep that to a minimum, especially for essential entities such as comments. It''s handy to see from just looking at your controller what data you''re providing. Sure, small queries in a helper is fine, i.e count rows, getting user''s real name etc. Don''t burry things away to quickly, you may know where they are now and what they''re doing, but 6 months after your site has gone live are you still going to remember so readily? On 31/08/06, Nicjac <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > I am relatively new to RoR and I am trying to implement a simple content > management system. I know I am reinventing the wheel but you don''t learn > much using someone else''s code. > > So anyway, my website has a main controller. I use a layout "main" > shared by all the controllers on the website (using the layout ''main'' > declaration in the controllers). In the layout, I use an > application_helper to display informations related to the user (if he > has messages, logged or not, etc..) which selects the right partials to > render (if not logged in -> display the log in form, if logged -> > display user infos) > > The problem : RoR is looking for the partial files in the view directory > of the currently used controller. It''s fine as long as I am using the > main controller. But if for exemple the users wants to modify its > profile (which is hadnled by the user controller), there''s an error > stating that partials cannot be found in the controller views. > > Is it a design flaw on my part or is there a way to have partials > availaible for all controllers so I can use them in a single layout for > my whole application ? > > > > Thanks in advance ! > > > > > Nicolas Jaccard > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hello, thanks for your thoughts, as I said im new to this design philosophy ! My helper doesn''t actually trigger a query, as it uses an object stored in the application_controller which contains the user informations if he''s logged on (it uses session stored user_id to fetch the data) Is it a good thing to do or not ? And when you talk about burrying stuff away, how would you actually display the user informations ? I first thought of just using the helper without partials but doing view related stuff like formatting in an helper didn''t seem right. I really appreciate the help! Nicolas Jaccard -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Loading in the controller and providing it to the views is fine, that''s what I do. Using the stored user_id is fine yes. Remember to ensure that the requested data actually applies to the logged in user though, and not a different one. Definitely use a partial for that, helpers are intended for providing information, not HTML. for example: in the controller: @user = User.find(params[:id]) # find sanitizes the id for you if user_logged_in?(@user) @profile = UserProfile.find(@user) end in the view: <% if user_logged_in? %> <%= render :partial => ''user/profile'' %> <!-- uses the @profile instance variable we created in the controller --> <% end %> in the partial: <!-- helper --> <%= get_friend_count(@user) %> You could put the friend count query in the controller, but as your actions get more complex and have a wider range of rendering possibilities, you may find you don''t always little things such as this, so it''s nice to put them in a helper. But make sure you don''t duplicate your queries when doing this! DISCLAIMER: I''m fairly new to Rails myself, don''t please don''t take everything I''ve said as fact! Ian. On 31/08/06, Nicjac <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > thanks for your thoughts, as I said im new to this design philosophy ! > My helper doesn''t actually trigger a query, as it uses an object stored > in the application_controller which contains the user informations if > he''s logged on (it uses session stored user_id to fetch the data) > Is it a good thing to do or not ? > > And when you talk about burrying stuff away, how would you actually > display the user informations ? I first thought of just using the helper > without partials but doing view related stuff like formatting in an > helper didn''t seem right. > > I really appreciate the help! > > > > > > Nicolas Jaccard > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---