small medium large xlarge

Generic-user-small
26 Aug 2010, 03:30
Bharat Ruparel (148 posts)

Sam, I am trying to port a Rails 2.3.8 app to Rails 3.0 and controller specific layouts do not seem to work. Here is the problem:

I have an admin section in my rails 3 app. where I want to use a different layout than the main layouts/application.html.haml layout. Here is the snippet of the admin_controller.rb:

class AdminController < ApplicationController

current_section :admin layout :admin . . end

Here are the contents of the layouts/admin.html.haml file:

  • content_for :secondary_nav do

    = navigation :second_level_admin

= render :file => “layouts/application”

Rails 3 is ignoring the admin layout all-together. Rails 2.3.8 doesn’t. Is there an existing bug in Rails 3?

Bharat

Samr_small_pragsmall
27 Aug 2010, 00:27
Sam Ruby (634 posts)

While that does sound like a bug, I am not aware of any bugs in that area. They layouts that I have tried continue to work.

Generic-user-small
27 Aug 2010, 12:44
Bharat Ruparel (148 posts)

It is a bug. I have gotten around it with ugly coding. So no worries. But I have opened up a ticket on lighthouse:

https://rails.lighthouseapp.com/projects/8994/tickets/5465-layout-in-rails-30-release-candidate-1

Other people have had similar experiences, see the thread:

https://rails.lighthouseapp.com/projects/8994/tickets/5371-layout-with-onlyexcept-options-makes-other-actions-render-without-layouts

The problem occurs when you are using nested layouts.

I want to take this opportunity to share some of my thoughts with you. I have purchased a copy of this book for every release including this edition. The third edition was the best in the sense that it combined basic rails skills with deeper discussions of intermediate/advanced topics. That is what more experienced people like me pay for. We don’t mind you writing for the newcomers to Rails (we were there once ourselves :)). But try to mix some of the more advanced topics in your book along with the introductory materials. I am glad to see you delaying the final release a bit. We can help shape the more advanced materials by sharing our problems/experiences.

Like this particular use/case. Layouts in Rails are very easy to implement, it is with more advanced topics like nested layouts that you go to yet another level all-together. Moreover, if things break from one release of rails to another, then it is this kind of knowledge that will help the readers of this book. I managed to get around this issue with some browsing through google reference and more specifically the tickets opened in Lighthouse.

So in a nutshell, some materials in the book which is beyond introductory will be quite useful don’t you think?

Regards,

Bharat

Samr_small_pragsmall
27 Aug 2010, 15:08
Sam Ruby (634 posts)

Bharat: can I ask you to be more specific? Ideally as it relates to this particular instance?

In the print edition of edition 3, the in depth coverage of layouts is on pages 545-552. In the beta 7 PDF edition of edition 4, the in depth coverage of layouts is on pages 363-370.

Can you point to exactly what was present in edition 3 that is not present in edition 4 that would have made the identification of this bug (great job, BTW!) easier?

Generic-user-small
27 Aug 2010, 17:36
Bharat Ruparel (148 posts)

Hello Sam, Thanks for your quick response as always. What I can do for you is to give you a link to my open source project that shows the problem. I have developed a commercial application for a health care company for them to share their documents in the cloud from all over the world. It is written in Rails 2.3.5. I upgraded it to Rails 2.3.8 and in the process of finishing up the upgrade for Rails 3.0. That will show you exactly the problem that I have run into. Actually, I will put up both Rails 2.3.8 and Rails 3.0 projects. The applications are generic since the customer was kind enough to give me permission to extract a generic implementation and put it out in the open source community.

As per the beta pdf 7.0, I downloaded it and read through it before posting my post above. The layouts coverage that you have is quite good really, but does not go far enough. What If you could address nested layouts where a controller does not use the default application.html.erb (haml) layout and uses its own layout to may be override it or supplement it then you will see the bug that I am talking about.

My target posting my Rails 3.0 code on Github is coming Monday, I will post the URL here once I am done doing it. That way you can download my code and try it for yourself? Does that work for you? Bharat

Samr_small_pragsmall
27 Aug 2010, 18:26
Sam Ruby (634 posts)

Bharat: that’s a different topic. You found a bug in Rails 3.0, and are working with the Rails Core team to resolve it. That’s all goodness. I doubt I can add much value there. My role is in documenting Rails.

I was responding to the following statement:

The third edition was the best in the sense that it combined basic rails skills with deeper discussions of intermediate/advanced topics.</blockquote>

Here I will disagree with you. The second edition was the best in that regard, but it only covered Rails 1.x. The third edition of the book is larger than the second edition, but less comprehensive. And neither directly covered the scenario you are now having trouble with.

Meanwhile, the state of Rails documentation has dramatically improved, particularly when compared to the Rails 1.0 days. The Rails guides are pretty good. And if I see things that need to be fixed, I can talk to the people who are developing them, and they get fixed.

But — in my opinion — I still don’t think that these guides are approachable by beginners. They are a great place to go if you know how to ask the right question. But until you know the right question to ask, they are not very helpful.

Furthermore, there is enough differences between Rails 2 and Rails 3 that even people who thoroughly know Rails 2 will need a bit of re-education to once again know what the right questions are to ask.

Generic-user-small
27 Aug 2010, 22:18
Bharat Ruparel (148 posts)

Sam, I think we are getting closer in understanding what each of us is talking about. Similar to this forum, I have been in contact with Ian Dees who is co-authoring the Using JRuby book. As I was going through the book, I found a few problems (after all, it is in beta :)), but more importantly, he and I engaged in an active dialog in what CONTENT could improve the book and I am delighted to see that he has followed up on it.

So, what I am saying here is that Rails should not be documented in a vacuum. It has to reflect what works and what has changed. For example, if you see the threads that I mention above, you will see that there are no specific resolutions to the deviations from the standard documentation that is provided by Edge Guides or yourself. So I am merely suggesting that you try out nested layouts and you will see that it contradicts what you are writing in the book. There is always a chance that I am wrong and I would humbly accept it when and if I am proven wrong.

Regarding my comment above “The third edition was the best in the sense that it combined basic rails skills with deeper discussions of intermediate/advanced topics.” It is entirely possible that it is a function of my learning curve too. I was intensely engaged in working on two Rails projects last year and may have found more use of the Third Edition since it was directly applicable to what I was doing then. So, that is a possibility.

I thought that you wanted to keep the more experienced developers interested, so that is where I was coming from. The shopping cart example is very good for beginners and you should keep it there. Go a bit beyond what the Edge Guides are telling us in your in-depth coverage of Rails that is based on what currently works and what does not work and what are the work arounds. For example, the behavior of content_for and yield has changed in some subtle but important ways which I found by listening to Ryan Bates and googling around. That kind of information in a book format is invaluable.. That is what I was leading up to. As you yourself point out above “Furthermore, there is enough differences between Rails 2 and Rails 3 that even people who thoroughly know Rails 2 will need a bit of re-education to once again know what the right questions are to ask.” you are right on target and I have first hand experience of that fact in trying to upgrade my project to Rails 3.

Samr_small_pragsmall
28 Aug 2010, 11:42
Sam Ruby (634 posts)

I think we are getting closer in understanding what each of us is talking about.</blockquote>

Agreed!

the behavior of content_for and yield has changed in some subtle but important ways which I found by listening to Ryan Bates and googling around</blockquote>

Thanks! Will investigate. Very helpful.

Go a bit beyond what the Edge Guides are telling us</blockquote>

While there will be instances where that is done, I’ll be upfront and will state that that there is no intent to do that in a systematic or comprehensive way.

First, “beyond the edge” is too volatile. Heck, the rate of change of Rails already stretches the limit of what can be said about basic concepts in a book intended to be printed.

More importantly, the focus of this book is on things that most people will need to know. Every section has been scrutinized from a “why do people need to know this?” perspective. In many cases, the fix was to simply add additional explanation as to why directly in the book itself. In some cases this involved pruning.

Note: none of what I have just said is in any way intended to suggest that subtle but important changes to existing methods won’t be reflected. I do intend to investigate that, and incorporate what I find back into the back. Once again, thanks for the heads up!

Generic-user-small
28 Aug 2010, 16:58
Bharat Ruparel (148 posts)

Sam, I think you are doing one heck of a job with this book, and I say this sincerely, so keep up the good work. I think Rails is invalidating the usefulness of a printed text which is a snapshot in time. In reality Rails is a fast moving “trunk” in terms of a Subversion analogy or the “master” for git. I think the market will be a lot better served by going to a subscription model and just pushing out electronic content (pdfs etc) and updating it more frequently for the duration of subscription. Pretty similar to what Michael Hartl has done with his Rails Tutorial. Bharat

Generic-user-small
30 Aug 2010, 00:53
Bharat Ruparel (148 posts)

Hello Sam, As promised, please the examples at the following URLs:

http://github.com/bruparel/file_manager238 - with Ruby 1.8.7-p299

http://github.com/bruparel/file_manager3 - with Ruby 1.9.2-p0

Let me know if I am missing anything.

Regards,

Bharat

You must be logged in to comment