link to - Making a conditional link_to statement in Rails? -


in code below, i'm trying make that, if user has accepted invite, they'll able click on "not attending" div decline invite.

that bit of logic works fine, i'm trying "not attending" div shows regardless of whether user has accepted invite.

right now, div appears if user has accepted invite.

is there way make link_to statement conditional, preserve div regardless? (that is, make div present, link if user's accepted invite?)

<% if invite.accepted %>     <%= link_to(:controller => "invites", :action => "not_attending") %>                                      <div class="not_attending_div">              not attending         </div>     <% end %> <% end %> 

<%= link_to_if invite.accepted ... %> 

http://apidock.com/rails/actionview/helpers/urlhelper/link_to_if

edit:

link_to_if uses link_to_unless uses link_to 's code, should work same same options

  def link_to_unless(condition, name, options = {}, html_options = {}, &block)     if condition       if block_given?         block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)       else         name       end     else       link_to(name, options, html_options)     end   end 

example

<%=    link_to_if(@current_user.nil?, "login", { :controller => "sessions", :action => "new" })      link_to(@current_user.login, { :controller => "accounts", :action => "show", :id => @current_user })    end %> 

check here http://apidock.com/rails/actionview/helpers/urlhelper/link_to_unless

edit:

does achieve need. sorry, not reading question better.

<div class="not_attending_div">    <%= link_to_if invite.accepted, "not attending", (:controller => "invites", :action => "not_attending") %> </div> 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -