The code you have makes the text a child of the <br> element; which is undesirable. I think you really meant:
%br - if @page.nil? (nothing yet) - else
To do this, you can simply:
%br
or
%br = @page.nil? ? "(nothing yet)" : @page.name
Or simply:
<br>
However, personally, I would "fix" this in the controller so that you always have an @page , with something like:
unless @page @page = Page.new( name:"(nothing yet)", β¦ ) end
With this, you can fill out the one that looks like a new / blank / insignificant page and let your view treat it like any other. Your @page will still not have @page.id , so you can use this for tests to decide whether you are creating a new element or editing an existing one.
Here's how I handle all my forms that can be used to create or edit an element: provide default values ββby creating (but not adding to the database) an element with default values.
Also: you create <br> , which will almost never be a good idea , and you create it with Haml, which should not be used to mark up content . You can step back and think about what you are doing.
source share