2

This is a bug I am only experiencing only in chrome and is only happening on a specific route - /dashboard/friends. The html is appearing as plain text, that is wrapped inside a

<pre style="word-wrap: break-word; white-space: pre-wrap;">

If I make any change to the contents of the files associated with the view like simply putting "blah" in the index.haml file it will then render properly. Anyone have any idea about what might be causing this?

EDIT: this is what renders in the browser -

<html>
  <head>
  </head>
    <body>
      <pre style="word-wrap: break-word; white-space: pre-wrap;">
       "my apps view renders in here including the head and html, 
        but since it is in quotes, it just appears as plain text
        <!DOCTYPE>
        <html>
        entire rails app html here...
        </html>"
</pre></body></html>

the bug seems to be related to the @invites variable I have in the controller, removing it fixes the issue -

class Dashboard::FriendsController < Dashboard::BaseController
  def index
    @friends = current_user.friends
#removing the @invites var fixes it, but I need those invitations...
    @invites = current_user.invitations.where(type: "FriendInvite").includes(:recipient)
  end
end

In the index.haml

%header.page-hdr
  %h1
    Friends
  %ul
    %li
      = link_to dashboard_find_friend_path, class: "btn" do
        .fa.fa-plus
        Add a Friend
.row
  - if @friends.empty?
    You have no friends
  - else
    - @friends.each do |friend|
      = render 'friend', friend: friend
  - if @invites.present?
    %h2 
      Invited
    - @invites.each do |inv|
      = render partial: 'invite', locals: {inv: inv}

This is the layout.haml -

!!! 5
%html
  %head
    %title= full_title(yield(:title))
    = stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true 
    = javascript_include_tag "application", "data-turbolinks-track" => true 
    = csrf_meta_tags 
    = favicon_link_tag '/favicon.ico'
    = favicon_link_tag '/favicon.png', rel: 'apple-touch-icon', type: 'image/png'
    %script{ type: "text/javascript", src: "//use.typekit.net/gey0efl.js" }
    %script{ type: "text/javascript"}
      try{Typekit.load();}catch(e){}
  %body#dashboard-body    

    = render current_user.navigation

    #dashboard-wrapper
      = render "shared/dashboard/header"
      = yield

UPDATE: upgraded to Rails 4.1, no luck. Again only breaking in chrome, and only when I include that second instance variable AND, that variable has been modified in some way( new record added)

Matt Ramirez
  • 673
  • 6
  • 19
  • related code = ? Tried using [raw, h or html_safe](http://stackoverflow.com/questions/4251284/raw-vs-html-safe-vs-h-to-unescape-html) to unescape html? – manu29.d Jun 05 '14 at 17:27
  • "You have no friends". So harsh :( – nzifnab Jun 05 '14 at 18:39
  • haha, placeholder of course ;) – Matt Ramirez Jun 05 '14 at 18:39
  • I'm not actually seeing the code that renders the `pre` tag here? Where's that at? – nzifnab Jun 05 '14 at 18:40
  • I have no idea where its coming from honestly, its realllly wierd, and only an issue in chrome. – Matt Ramirez Jun 05 '14 at 18:41
  • 1
    Rightclick-view source shows the `pre` tag there? What does your `layout.html.haml` look like? And have you tried changing the name of `index.haml` to `index.html.haml`? It might be because the extension doesn't include `html`... – nzifnab Jun 05 '14 at 18:42
  • Yep, shows up when I inspect source, no idea where it comes from, I put the layout file in there. Im going to try adding the .html extenstion. EDIT: didnt work, and it is definitely related to the @invite var – Matt Ramirez Jun 05 '14 at 18:46
  • I'm not seeing a `body id='dashboard-body'` tag in the markup you showed being rendered to the browser, but that's what your layout file says :\ Is that tag *inside* the pre element also? – nzifnab Jun 05 '14 at 18:53
  • Yep, everything from the app is inside that pre element. – Matt Ramirez Jun 05 '14 at 18:55

1 Answers1

3

Turns out that the problem was the lack of extension on the file that was being rendered. All my views where .haml files, changing them to .html.haml fixed this problem.

Matt Ramirez
  • 673
  • 6
  • 19