RailsCasts Pro episodes are now free!
Learn more or hide this
The first thing i do on monday morning is check the new railscasts episode. Thank you for your little but powerful tips and hints :D
Greetings from Germany
the third example (style-sheet trick) has some negative implications for the accessibility as screenreaders still don't treat display:none consitantly.
Some will still read the link to the user, this may not be as bad in a single occasion but makes this technic to an anti-pattern in my view as this will accumulate to many wrong placed/unnecessary content for some of the users.
I'd have to agree with Nicolash, hiding content that should never be displayed through css seems like a bad idea. Also having partials specify what stylesheets to load sounds like asking for problems maintaining the app later on but maybe that's just me ;)
Other than that another great 'cast! Hard to believe it'll be 100 next week already.
Good stuff as always, but ERB is so 2007... how about some HAML!? ;-) Jack will back me up on this.
Love the RailsCasts. I also look for them every Monday morning.
I also have to agree that hiding things via CSS that really shouldn't be displayed just strikes me as a bad idea. There may be situations where it might be OK, but I really can't think of any offhand.
However, I did love the 2nd example. How is it I've made it this far without realizing I could pass blocks to a yield in a partial? THAT is going to be extremely helpful, I think.
Thanks again for the great screencasts.
Is it possible to make groups in a partials (maybe with header and footer)
Thanks for the great work you accomplish.
Great screencast - thanks Ryan. I loved method 2 - something that I'll look at using a bit more.
You seem to have 2 helper methods in your view code:
...are these helpers that you have written yourself or are they built into Rails?
@DAZ - both of those helpers are built in to Rails. Check them out on the API.
Great episode, Ryan. I'll be coming back to this one a few more times. I'd agree with the other guys about the display:none, though.
I started using the current_page? method for css hooks on navigation and subsequently ran in to the appended url issue during search/pagination. I've yet to find a clean solution for a two tier tabbed navigation with highlighted current tabs - maybe this would make a good follow-up episode? I'd be interested in seeing the workarounds for the url comparison...
p.s. I find it strange that current_page? (:controller => :users) only returns true on the index action. Has anyone else noticed this?
@Neil - To answer the PS, the reason it does that is the route builder defaults to :index if you do not pass an action. When you want to ask if something is the current page it compares the route to the hash passed. If you don't pass an action, it assumes you mean index.
If you want to check the current controller only you could use something like
Then, in your view you can find out if you are in a particular controller (or even array of controllers) like...
link_to_unless current_controller?('home'), 'Home', home_path
link_to_unless current_controller?('admin_users', 'admin_posts'), 'Admin', admin_path
Ryan, I am fairly a newcomer to the Ruby on Rails world over from Coldfusion. I must admit that your 'FREE' Railscasts are simply superb! Keep up the good work, you have my support!
First, thank you!
I have been noodling on how to handle various forms of similar views and think this topic warrants more episodes up here. While it's great that examples are simple by necessity, they may fall down in practice when reality strikes :-)
It's certainly the case that new vs edit forms warrant a form partial, for example. But in almost all cases it seems like there's some conditional logic depending on newness. So this means some logic in the controller, a helper or in the partial via locals, in other partials, etc. But what's the best practice?
For example, I have projects that HABTM resources. A resource can exist without a project, but is often created to be associated to that project when saved. The forms for editing are all one partial, but my Save and Back links are all a little different, and some wording and even UI varies a little depending on context. There's too much repetition to keep it DRY, but enough logic to be hairy.
It would be great to hear more about how things can be kept clean in slightly more complicated cases.
Thanks again for doing what you do.
Hello Ryan (and railscasts guys),
I'm trying to render a layout through rjs but it looks like Rails doesn't render it.
page.replace_html :wrap, :layout => "details", :object => @task do
Am I missing something or Rails doesn't allow rendering a layout into a rjs file?
Hi Ryan, I noticed that you have switched to new shortcuts key tools from this episode. Can you tell me what it is?
This tip is powerfull but it's really hard to use it correctly.
Really need a good conception before.
Thanks Ryan for all you do.
It this episode I'm having a problem with the stylesheet helper.
I'm trying to put a stylesheet into a partial and it's not being brought into the cascade. I believe this is because the head is rendered before it pulls in the partials.
Is there a work around for this? I'm guessing this wouldn't be the best practice, but I sort of like the idea of being able to have snippets of css loaded only when needed by the partial. Plus it helps clean up my one GIANT application.css file.