开发者

Rails app generating extra output

开发者 https://www.devze.com 2023-02-09 22:27 出处:网络
Im trying to fool around with a rails application to learn the proper way of doing things, and i\'ve gotten a great start, but now theres this thing bugging me. Its pretty cosmetic, but it bugs the h*

Im trying to fool around with a rails application to learn the proper way of doing things, and i've gotten a great start, but now theres this thing bugging me. Its pretty cosmetic, but it bugs the h*** out of me.

I've made this session controller and session helper to take care of logging in and out, and i believe this works fine (havent actually tested it yet), yet when i want to use if the !signed_in?, i get extra output in my view (where im using haml), below is all code i believe is involved in generating this extra output.

sessions_helper.rb:

def get_current_user
  @current_user ||= false
end

def signed_in?
   !get_current_user.nil?
end

partial: _menu.html.haml (im still learning to make this look ruby-isk)

%nav
  #userbox
    =if signed_in?
      =link_to 'Create User', :signup
      |
      =link_to 'Log In', :signin
    =if !signed_in?
      =link_to "My profile", :root
      |
      =link_to 'Log Out', :signout
  %ul
    %li= link_to 'About', :about
    %li= link_to 'Concept', :concept
    %li= link_to 'Home', :root

This ends up with generating the following html:

<nav> 
  <div id='userbox'> 
    <a 开发者_Python百科href="/signup">Create User</a> 
    |
    <a href="/signin">Log In</a> 
  2

  </div> 
  <ul> 
    <li><a href="/about">About</a></li> 
    <li><a href="/concept">Concept</a></li> 
    <li><a href="/">Home</a></li> 
  </ul> 
</nav> 

The issue here is the extra number 2 generated. How do i remove that?


Try use - instead of = in ruby code who not render code:

%nav
  #userbox
    - if signed_in?
      =link_to 'Create User', :signup
      |
      =link_to 'Log In', :signin
    - if !signed_in?
      =link_to "My profile", :root
      |
      =link_to 'Log Out', :signout
  %ul
    %li= link_to 'About', :about
    %li= link_to 'Concept', :concept
    %li= link_to 'Home', :root

See here the documentation for run ruby code: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#running_ruby_

0

精彩评论

暂无评论...
验证码 换一张
取 消