Rails: Embed metadata in templates – YAML in my HAML? - ruby-on-rails

I would like to be able to set things like the page title and <meta> description from within HAML “pages” served up by my static page controller.
Is there a good way to do this? Ideally, I see it working something like:
Name files like about_us.html.haml.yaml
Use the normal render method
But now there is a hash of metadata available to my controller and layout templates, which set various headers and elements, respectively.
Thoughts?

(Since no one contributed a full answer)
If you want to set up title, description, noindex or similar tags in the head, then github.com/kpumuk/meta-tags is the best way to do it! I've used in a various projects, and think it's best gem ever for manipulating with title, description and other stuff that sits in the head tag.
— Dmitry Polushkin
It seems to work well for me, though it is a touch less powerful than what my question was looking for. Further answers welcome.

Related

Reference ActiveRecord attributes in textarea

I am building a simple invoice application, and I would like to allow the users to customize the text on the invoice. In addition to this, they should be able to reference specific attributes in my models, i.e. "This is a test {{Model.attribute}}", and once the text is parsed the tag is replaced with the value of that attribute.
I have looked a bit at redcloth, textile and handlebars, but it does look like a little bit overkill to be honest. For instance I would not like to allow the users to input any HTML.
I would really appreciate if someone could point me in the right direction. There is probably a gem for this that I just havent found yet.
Thanks in advance
I use liquid with simpleformat which will sanitise the text.

ViewModel in ZF2

I am working on a project and was wondering if anyone else has messed with the view model much. Im looking for some examples on how to inject other view models i.e header,footer content.
I already have the template and layout path switching Im just trying to figure out the best way to handle if I select layout1 and it has 3 footer content fields, and a slider so how would put a class in front of the render to gather and inject required data
EDIT
Ok I guess I should clarify LOL .... slight ADHD where my mind wanders.
What should I listen for before injecting the viewmodels or can I do this in my onBootStrap() in my main module. I currently
$sites = $e->getApplication()->getServiceManager()->get('Application\Model\Sites');
$sr = $sites->getSiteByDomain();
Since many domains and/or subdomains can point to this and puts info in a session. Maybe im over thinking it and should just extend actionController like I did in ZF1
LOL PHP so many ways to do something ......
Thx for any pointers
There's two helpful links i can give you. One is the playground of Rob Allen alias Akrabat, you can find his playground right over here at github. The other one would be the official documentation which is nicely documented on this part.
If those don't help you, you should specify your question and show us what you've tried so far.

incorporating all views into one view

Just wondering what the shorthand would be in Rails to do this (if any):
I have views/pages/ containing 5 html.erb files and they all use the same default layout.html.erb, with one yield statement in the middle of it (the standard setup).
Now I want one view that incorporates all 5 of those erb files above contiguously, one after the other, in place of the one existing yield statement in that same layout.html.erb.
What minimal changes would I make to the layout.html.erb to accomplish this.
(Rails Newbie - like it more than Django now).
Ah,
I see what you're saying. Try this. Have your file structure such that all the views for said controller are in one folder...
#controllers_views = Dir.glob("your/controllers/views/*.erb")
#controllers_views.each { |cv| puts cv }
Seems like that would work, I'm away from my dev box or I'd test it for you.
Hope that helps.
Good luck!
You could always have a javascript that requests the sequential yields at a time interval as an ajax request. Then just your target element change to reflect the updated information.
Alternatively load all 5 into different divisions, and have them revolve visibility, like a picture gallery. CSS3 could pull this off.
http://speckyboy.com/2010/06/09/10-pure-css3-image-galleries-and-sliders/

From db to css file?

I have a small set of css items in a db table that I need to turn into a css file to be included on a page. How can I do this in Rails3?
Is there a way I can call this directly from a stylesheet_link tag? Do I need to go through some ruby to open a file and output it in some directory first? Do I do this in a controller?
The css is actually its own model associated to the item using the css.
I do not know and looking for a solution found little yet, so asking here.
EDIT:
Simple when looked at, I was looking toward a sass or less solution and may still, but this is a simple start
I would create a Controller that retrieves the data from the database that uses a View to render the data to a Cascading Style Sheet.
You could then reference the given URL whenever you need to use the resulting stylesheet.
This is the easiest way that I have found http://blog.hasmanythrough.com/2007/10/18/simpler-than-dirt-restful-dynamic-css

Rails Dynamic tag generation from context

Let's say I want to trend all comments posted on a site and create dynamic tags. For example, If there are x number of comments that contain the word iPad I would like to create automatically create a tag called "iPad" and put it in a tag cloud.
Is this possible? I checked out the acts_as_taggable gem but it requires one to specify a tag, I guess I am looking for a way to generate tags from content.
Well something like the yahoo term extraction service might do the trick and there is a plugin for it http://expressica.com/auto_tags/.
Though it is not for commercial use.
Sure, this is possible.
Just parse the content of each comment as it's passed in and attach the tags you're interested in.
This can either work on a whitelist - where you specify all the tags you're interested in and attach those if relevant.
Or it could work on a blacklist - where you specify all the words to ignore, e.g. "the", "on". This approach is probably a lot more time consuming, but would allow for more dynamic results.
I would probably work on a white list, then have an ability to add new tags to the whitelist and have it go back and retroactively add the tags where applicable.

Resources