-
-
Save micahgodbolt/4991146 to your computer and use it in GitHub Desktop.
# Block syntax | |
<% | |
if !defined? title | |
title = "Default Title" | |
end | |
%> | |
<h2><%= title %></h2> | |
<p>Blah blah blah blah</p> | |
# Calling your partials | |
<%= render "/partials/block", :locals => { :title => "Past Events" } %> | |
<%= render "/partials/block", :locals => { :title => "Upcoming Events" } %> |
Thanks Jed! I'm still getting "undefined local variable or method `title'" - Do I need to do something different in my partial? Does it need to be @title? Pretty new to ruby here.
No, I don't think it should be @title.
I'm assuming that
<h2><%= title %></h2>
<p>Blah blah blah blah</p>
is the content of partials/block.erb
, correct?
That's correct. I've got it rendering just fine if I remove the <%= title %> but i get an error if I put it back in.
Just to make sure you know, this is in the context of using Serve (get-serve.com) not a rails project or anything.
Just noticed I was missing the closing brace on the second example. That could cause things to blow up. Fixed.
oh !!! hahah :) sorry! I accidently was calling it a previous time without the variable being stated.
Yup, that does the trick! thanks.
Oh last thing. I think it's render, not partial. Otherwise you can do <%= render :partial => "file/name" %>
Huh. I haven't used Serve, but I have used Sinatra on a lot of projects. I use sinatra-partial which gives me a partial
method, which is what my example was based on.
Glad I could help. Ruby is awesome. It's a breath of fresh air after 10 years of PHP.
This should do what you want.