Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Rails new/add/delete helper

Call: @registered_user_functions( @photo )@, get ( new | edit | delete ) links.
  def registered_user_functions( item = nil, show_new = true )
    # abstract name of html#id to update with javascript
    update_name = item.class.to_s.downcase
    if @session[:user]
      a = "( "
      a << link_to( 'new', :action => 'new' ) + " | " if show_new
      if item # is given to edit or destroy...
        a << link_to_remote( "edit",
              {:url => { :action => "edit", :id => item },
              {:href => url_for( :action => "edit", :id => item ) },
              :update => "#{update_name}-#{item.id}" } )
        a << " | "
        a << link_to_remote( "delete",
              {:url => { :action => "destroy", :id => item },
              {:href => url_for( :action => "destroy", :id => item ) },
              :update => "#{update_name}-#{item.id}",
              :confirm => "really delete this #{update_name}?" } )
      end
      a << " )"
    end
  end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed