I've been watching some Railscast episodes and it looks like he's using Sublime Text as his editor. How does he create new <% %> tags? I can tell he's using a shortcut but can't figure out what it is. Any help would be appreciated.
I really don't know what the "<% %> tags" are, but I imagine the presenter is using the ERB Insert and Toggle Commands add-on. The animated GIF on the project's description page shows such things being used.
Related
I'm barely beginning to understand Ruby on Rails and there are a lots of things I don't get to remember correctly, so I wonder if there's a way to enable suggestion and autocomplete for functions in html.erb files.
Right now it suggest me things when I'm working on ruby files, but this is not the case in html.erb files so I make a mess each time I try to remember how to do something until I find that I'm looking for 'yield' or 'provide'... I know is not a big help but I would love if sublime could suggest me this when I type 'y' or 'p' between <% %> tags.
there are a few packages you can check for sublime text 3 ,
https://github.com/matthewrobertson/ERB-Sublime-Snippets
https://github.com/CasperLaiTW/ERBAutocomplete
some convenience you can get are, just write
er and tab which will print <% %>
ep and tab which will print <%= %>
If this is about the autocomplete popup not showing while typing, rather than completions not working when pressing the Tab, you need add the scope to you auto_complete_selector setting. By default, Sublime Text shows this popup only when working in the source scope, even though you can force showing the popup when pressing Ctrl+Space. To change this, open your user preferences (Preferences > Settings User) and adjust the auto_complete_selector by adding the text.html scope (or the more limited text.html.erb).
I'm trying to implement redactor as a WYSIWYG editor with ruby on rails. Everything seems to be working fine except that when I edit text in the editor the html tags show up. This happens even when I use the html button on the toolbar.
So on the webpage the text appears something like this:
<p>Edited text here</p>
I haven't included any code because I'm not really sure where to begin looking with this so any help at all will be appreciated :)
when using a text editor you have to tell your rails app that the area is html safe.
This is (by default) not the case as people could attack your site by using a text box you have put into your app.
by declaring an area as html safe you should be able to use the html tags as you like.
be aware of the security risk for using this.
e.g.
<div class="description">
<%= #foo.foo_desc.html_safe%>
</div>
Hope this clears it up for you.
in your view try using raw before the text you are trying to show. For example
<%= raw #post.body %>
this will work out with the html tags and show the processed text only without the tags.
I'm writing a Rails application and I have button that I create as follows:
<%= button_to t('.upload_html'), ... %>
where the ... stand for the other options. So the button should have the text pointed to by .upload_html and it does. Now I want that text to have two lines. In the YAML file I had
upload_html: "turn off"
and now I want
upload_html: "turn<br>off"
with a line break inside the button label text. But this does not work. It displays the string literally including the HTML tag without linebreaking. What can I do to force the line break?
Thank you!!
Best, Patrick
did you try "turn<br>off".html_safe ?
I am trying to add Markdown to my Rails 3 web app but am having problems.
I have tried rdiscount and markdownizer but either they're not working or I'm not writing the correct code for them.
The code I have at the moment to display a text field is <%=h simple_format (#user.desktopinfo) %>
I want to increase the functionality of this text by adding Markdown but I am unable to get it work, please help! :)
EDIT 2
Using markdownizer broke my app, so I am now using BlueCloth. Add bluecloth to the gem file and add this <%= raw BlueCloth.new(#user.desktopinfo).to_html %>
:)
EDIT
Actually, just trying again...
With markdownizer, with markdownize! :desktopinfo in the user model and <%= #user.rendered_desktopinfo %> on the page that shows the text, I get this: <h1>this is a h1</h1> on the text when I enter
this is a h1
============
so I am halfway there! How do I now turn this code into html?
Consider rdiscount which substitutes for bluecloth but is faster and better maintained.
Ryan Tomayko's comparison is a good write up regarding the different libraries for using markdown in Ruby.
You haven't really specified exactly what you are after, but I use bluecloth when working with markdown. You can add 'bluecloth' to your Gemfile.
To parse your markdown it is as simple as:
<%= raw BlueCloth.new(YOUR_MARKDOWN).to_html %>
You need the keyword raw. so the HTML is not escaped.
<%= raw #user.rendered_desktopinfo %>
I've tried searching the web for a solution for this but havent been able to find any way of combining this.
Im printing html from a wysiwyg editor and found the simple_format helper to print the HTML with paragraphs etc. The problem is that it strips embed tags from the code aswell.
Do any of you know a way to print content from a WYSIWYG that adds paragraphs, br's, strong/bold and keeps all media such as images, embed's, etc.
Thanks!
Incase anyone is interested i solved it with:
<%= simple_format(content.post_content, {}, {:sanitize => false}) %>