Skip to content

Instantly share code, notes, and snippets.

@micahgodbolt
Last active December 13, 2015 23:19
Show Gist options
  • Save micahgodbolt/4991146 to your computer and use it in GitHub Desktop.
Save micahgodbolt/4991146 to your computer and use it in GitHub Desktop.
Partial specific variables using get-serve
# 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" } %>
@jedfoster
Copy link

Just noticed I was missing the closing brace on the second example. That could cause things to blow up. Fixed.

@micahgodbolt
Copy link
Author

oh !!! hahah :) sorry! I accidently was calling it a previous time without the variable being stated.

@micahgodbolt
Copy link
Author

Yup, that does the trick! thanks.

@micahgodbolt
Copy link
Author

Oh last thing. I think it's render, not partial. Otherwise you can do <%= render :partial => "file/name" %>

@jedfoster
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment