<%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %>
Notice how RubyMine formats the code with 2 and 4 spaces of indentation. This is not consistent and very annoying. I tried changing the indentation in Settings, but there isn't a separate tab for ERB files.
Actually, the indentation is inconsistent. It's 4 spaces, then 2 spaces. Sometimes, the HTML elements are indented 2 spaces. Other times, they are indented 4 spaces. Some ERB script elements are indented 2 spaces. Some are indented 4 spaces. There is no logic to the indentation. I think it's a bug.
Here's the original file:
<%= form_for(@user) do |f| %> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %>
I can confirm I have the same issue. My team style is 2 spaces everywhere, yet CMD-SHIFT-L or TAB gets me 4 (even with the XML suggestion). I have to manually indent with the space bar and try to avoid formatting code when I work with ERB. It's not just annoying, it attracts criticism from the team (who already think less of me for using an IDE rather than a text editor!). When working with views I switch to Sublime Text or vim - Rubymine is not up to it right now, sadly.
Could you please provide the situation where the indentation is incorrectly used?
Regards, Oleg.
Here's an example:
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %>
prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div >
<%= f.label :email %>
<br/>
<%= f.text_field :email %>
</div>
<div >
<%= f.label :password %>
<br/>
<%= f.password_field :password %>
</div>
<div >
<%= f.label :password_confirmation %>
<br/>
<%= f.password_field :password_confirmation %>
</div>
<div >
<%= f.submit %>
</div>
<% end %>
Notice how RubyMine formats the code with 2 and 4 spaces of indentation. This is not consistent and very annoying. I tried changing the indentation in Settings, but there isn't a separate tab for ERB files.
I am using RubyMine 5.4.3.2.1 on Mac OS X.
Joseph
You can try to change xml code style settings for ERB formatting
Oleg.
Can you show me how to get to that option? I searched for erb, and the only option that showed up is:
Colors & Fonts.
Hi,
I meant that ERB uses XML code style settings, so you can change them.
Regards, Oleg.
Nope. That didn't work. See screenshot below.
Could you test out your solution before you suggest it? It's getting annoying.
Hmm, it looks like you do not like indentation of <li> in
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
If so, there is no way to fix it :( And it looks like a bug for me. So, please file it in our tracker (http://youtrack.jetbrains.com/issues/RUBY).
Thanks, Oleg.
Actually, the indentation is inconsistent. It's 4 spaces, then 2 spaces. Sometimes, the HTML elements are indented 2 spaces. Other times, they are indented 4 spaces. Some ERB script elements are indented 2 spaces. Some are indented 4 spaces. There is no logic to the indentation. I think it's a bug.
Here's the original file:
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %>
prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div >
<%= f.label :email %>
<br/>
<%= f.text_field :email %>
</div>
<div >
<%= f.label :password %>
<br/>
<%= f.password_field :password %>
</div>
<div >
<%= f.label :password_confirmation %>
<br/>
<%= f.password_field :password_confirmation %>
</div>
<div >
<%= f.submit %>
</div>
<% end %>
I can confirm I have the same issue. My team style is 2 spaces everywhere, yet CMD-SHIFT-L or TAB gets me 4 (even with the XML suggestion). I have to manually indent with the space bar and try to avoid formatting code when I work with ERB. It's not just annoying, it attracts criticism from the team (who already think less of me for using an IDE rather than a text editor!). When working with views I switch to Sublime Text or vim - Rubymine is not up to it right now, sadly.
I am also unable to use 2 space indentation in ERB (.erb) files.
I tried changing the XML indentation settings, but it has no effect on ERB files for me.
Is there another work-around for this? Wouldn't it make more sense to have a dedicated settings section in Editor > Code Style > ERB?
I'm not the only person with this problem it seems:
https://youtrack.jetbrains.com/issue/RUBY-16183
Setting tab size and indent in Editor > Code Style > Other File Types fixed the issue for me.
@James Reidsmith, thanks for your replying.
It's very helpful!!!
@James Reidsmith thanks!