I've finally decided to give angularjs a whirl and i'm running into some early trouble.
I'm using Rails 3.2 and the Slim template gem for the view.
I'm just trying the example from the angularjs site here: http://angularjs.org/#todo-html
Here's the relevant bit:
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span>
Which in slim would be something like:
div(ng-controller="TodoCtrl")
span {{remaining()}} of {{todos.length}} remaining
The problem is Slim just prints:
{{remaining()}} of {{todos.length}} remaining
literally as a string.
Anyone able to get Slim and Angular to play together?
I finally got it to work.
I had to go into my layout and do this:
html(ng-app='')
You can probably add that to a div on the particular page also.
div(ng-app='')
div(ng-controller="TodoCtrl")
span {{remaining()}} of {{todos.length}} remaining
Hopefully this helps someone. It took me a bit to figure out.
You can also do it like so:
html [ng-app]
Or:
div [ng-app]
div [ng-controller="TodoCtrl"]
span {{remaining()}} of {{todos.length}} remaining
Related
Details first:
Rails ver 5
using slim template
deployed on heroku
Since upgrading to rails 5, my app sometimes print out html tags as text.
As seen above, the code in the layout prints out just fine. But codes that is yielded in the layout is wrong.
The code yielded is cached, does this affect the rendering?
Any thoughts on why this might be happening?
EDIT:
My layout code
The Index View code
The rendered html (sometimes it is escaped, so not always, sometimes it works)
Thank you
Found it, it was the caches_action acting up, not really sure why it caused it.
I don't really have a big issue and my bad if it's obvious but I couldn't find this on SO or google which is quite rare, anyways... I'm using Ruby on Rails to create a pattern library which ofcourse contains code snippets to go along with examples, now what I did was create a partial in a folder somewhere in my views - now it's no problem to render this partial using:
= render partial: '/snippets/grid/single-column.html.slim'
However, for these snippets I would also want to render the actual source of the slim file itself e.g.
.container
ul.test
li: a href="#"
li: a href="#"
li: a href="#"
li: a href="#"
I would like the output of the 'plain' render to be as the above snippet.
The reason for doing this is that I'm using Google Code Prettify to beautify this code for readability and since we're using slim as a templating engine here it's easy to just copy the snippet and paste it into a view anyways.
I'm not sure wether or not this is possible or if this type of rendering has a specific name - If so please do tell :)
For reference I looked in the following places to see if I could get a grip on this:
github - rails render
apidock - rails render
slim-lang - verbatim text
However I did not find my answer here.
Furthermore I'm a freshman when it comes to rails so I haven't got alot of experience yet in building these kinds of functions (it's nice to understand the resources you're working with ;)).
As usual, all help is appriciated.
Thanks in advance - Sidney Liebrand
EDIT
Yeah, what might also be smart is to include rails / slim versions:
Rails 4.2.1
Slim 3.0.1
You have to read the content of the file like a string in the controller for example:
#code = File.open('app/views/snippets/grid/single-column.html.slim').read
And in the view something like this:
<code class="prettyprint"><%= #code %></code>
I'm converting some existing HTML files to Slim (https://github.com/stonean/slim) and using it for the first time but I'm having problems getting lists to work in compact form (meaning all on one line rather than indented below). The docs say:
Inline tags
Sometimes you may want to be a little more compact and inline the
tags.
ul
li.first: a href="/a" A link
li: a href="/b" B link
But when I try that I get this output in the browser:
a href="/b" B
With the rendered HTML looking like this in the source:
<li:>a href="/b" B link</li:>
Any ideas why this isn't working and how to fix it?
Your syntax is correct and the output for me (slim 1.3.0) is, as expected:
<ul><li class="first">A link</li><li>B link</li></ul>
You should check your slim version and update appropriately.
I am having trouble in using tinymce editor with rails 3. I want to show text in bold letters and having trouble using tags like when I write something in p tags It should go to next paragraphs. in my case this tags is not working. It remains on same lines and display p tags on site page.
The usual suspect when it comes to rails 3 printing raw html output to the site, is that someone forgot to call html_safe on whatever text should be printed.
So if you have a #my_model_instance.description that you edit with tinymce, you might want to make the view look like #my_model_instance.description.html_safe, or as they suggest in the comment on the documentation, raw(#my_model_instance.description).
If the text is coming from user input, however, you might want to be a bit cautious, since it might be possible for users to input all sorts of nasty injection hacks this way.
I'm looking for a tutorial or a piece of code that can leads me to create a page
where we can find only 10 data rows per page and navigating with Ajax previous/next arrows
and also page number (i.e.: < 1 2 3 ... 10 > ).
Thank you very much.
A good place to start is Mislav's will-paginate plugin. The Readme at that link should explain how to use it.
Edited:
There's also a screencast on RailsCasts about Ajax pagination. I haven't watched it, but his stuff is usually really high-quality and easy to follow.
it's not ajax but maybe it's useful for you... when you use haml and haml_scaffolding in rails it's authomatic the pagination using this kind of sacffolding