suggest .erb 'functions' in sublime - ruby-on-rails

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).

Related

ruby on rails: text filed formatting

I tried to copy and past from Word document to text field using Ruby on Rails.
But all formatting( spaces, bold and other) are disappeared on text filed.
I've just got the simple lines of text without any formatting.
I've read that need to use Simple format tool... but I want that a user be able just to copy and past a text to text field without doing any adjustments.
I mean, I want make all adjustment in advance and the user could just copy and past the text and got all formatting, the same as in Word doc.
The link to file with text field as below.
https://gist.github.com/tatyana12/2f9d39c2f6e4f8fabea5e70e11eaf310
Also I have Application.html.erb file:
https://gist.github.com/tatyana12/15c27d542091b04f3c3adfdfd252b7f4
How to initialize editor if I don't have id = "edit" right now?
How to put some code extra style to this file?
Have a go at wrapping your field in your show.html.erb or wherever you want to display it with simple_format, for example:
<%= simple_format(#object.description) %>
See http://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format for more info.
I've solved this problem by implementing SKEditor.
There is a lot of tutorial how to implement this editor.
I (as a lot of other users) have problem that my text wasn't formatted because this editor is not compatible with turbo links.
So, I disable turbo links in some files, and as result I have the text formatted.

Adding forms in non-form pages in ActiveAdmin

I'm trying to add a simple select box and submit button to a "show" page in ActiveAdmin. Basically, the clients wants a simple way to assign a currently unassigned widget to the item currently being viewed. Not that that really matters.
What I am seeing is that although I can add a form and a select box, if I try to add anything after the select, the select doesn't get displayed. It's not that it is hidden by CSS, but that it just doesn't render.
Here's the relevant code:
column do
panel "Devices without locations" do
devices = Device.without_location
form_tag add_device_admin_location_path do
select_tag(:device_id, options_from_collection_for_select(devices, :id, :name))
submit_tag
end
end
end
The submit tag will be displayed, but the select will not. event if I put "foo" in there, only the "foo" will show up. The only time the select will show up is if there is nothing else in the block.
Update:
Okay, so I've been able to work around this by concatenating the output together. It's not ideal, and I definitely feel dirty, but it works.
I tried using formtastic on this, but it appears to only accepts attributes from the model, this doesn't work: I'm updating the device, not the location.
This works, but if anyone has a more better way of doing this, I'd love to know.
i had the same issue, and moving form into app/views/admin/#{model_name}s/_#{partial_name}.html.erb worked for me fine

Is there a way to get Sublime Text 2 to autocomplete HTML attributes?

I was wondering if there is a way to get Sublime Text 2 to autocomplete HTML attributes like in Aptana?
Autocomplete is enabled by default when you use "<" and your tag and then hit enter. So if you enter <p and then hit enter it will finish out the tag pair for you... where you will end up with <p></p> and your cursor will be in the middle. You can change this to tab if you prefer by pasting the following into your Preferences -> Settings - User file:
{
"auto_complete_commit_on_tab": true
}
This will override the default value of false for completion on tab. Again that is only if you wish to use tab instead of enter.
Hey you may try https://github.com/agibsonsw/HTMLAttributes or install trought package control package called "HTMLAttributes" ;). Its works for me. For example you type:
<p then press space bar then ctrl+space and you got list of attributes.
You can try to use emmet package. It was made specifically for html&css code completion. For more information you should read the documentation.
I was having the same issue; although I use both plugin packages HTMLAttributes and Emmet, neither one provides the auto-complete functionality I was looking for that's similar to Dreamweaver's.
Solution: I found a package called SublimeCodeIntel that does exactly what I needed.
Example: I code html emails and do a lot of inline CSS. End goal:
<td style="vertical-align:top;">
After installing SublimeCodeIntel, I typed <td style="v and a list of CSS properties starting with "v" displays.
Using my arrow keys, I select vertical-align and press tab to confirm, then type the letter "t" and a list of CSS values now displays.
I select top and then press tab to again confirm my selection.
Note: You can create predefined snippets for Emmet for undefined CSS properties but I wanted something "out of the box" instead of having to a) learn how to create them via the documentation (though I'm sure it's simple), and b) create a snippet each time I came across an undefined CSS property/value like vertical-align.
Hope this helps.

sublime text 2 ruby

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.

can link_to lead to rendering sth?

i want to render a partial within a view. so that when button MORE is clicked everything stays the same just additional characters are shown. in my case the whole article.
<%= #article1.content[0..300] + "..." %>
<%= link_to "more", ....... %>
i dont know what the right methot would be. somehow i have to explain to rails that when button more is clicked it shows me the whole article. maybe i shouldn't use method link_to ..
thank you in advance for your replys
What you're looking for is link_to_remote or link_to_function.
link_to_remote will be fetching the rest of the article from your controller and replacing/appending to a DOM element with a partial via RJS. This allows you to minimize unnecessary data being sent, and facilitates handling users that have javascript disabled.
With link_to_function, the entire article will be served when the page is loaded, but the everything beyond the first 300 characters will be hidden by CSS. This is easier to set up but sends a lot more data, it also relies on the user having javascript enabled.
Without looking at the source the average user probably couldn't distinguish between the two methods.
Which choice you go with is up to you. Sorry, I haven't got time to provide code examples, but the internet is full of them.
try link_to_function, use truncate for part and insert hidden tag with full text, switch them using javascript in link_to_function

Resources