mercoledì 4 dicembre 2013

Rails 4 rescue_from Routing Error path sconosciuti

Per prima cosa in fondo a route.rb

# routes.rb 
# ultima istruzione del file altrimenti naconde quelle precendenti
match '*path', via: :all, to: "application#routing_error"

in questo modo redirigiamo tutti i routing sconosciuti

Quindi  andiamo a generare l'errore che gestiremo come meglio ci aggrada

# application_controller.rb 

def routing_error
  raise ActionController::RoutingError.new(params[:path])

end

rescue_from ActionController::RoutingError, with: :routing_error_rescue

private

def routing_error_rescue
  flash[:error] = "Impossible #{params[:path]}."
  redirect_to request.headers["Referer"] || root_path

end

Fatto

lunedì 27 febbraio 2012

lunedì 21 novembre 2011

Rvm & git info in console

due semplici istruzioni per ridursi il lavoro

export PS1="\[\033[01;34m\]\$(~/.rvm/bin/rvm-prompt) \[\033[01;32m\]\w\[\033[00;33m\]\$(__git_ps1 \" (%s)\") \[\033[01;36m\]\$\[\033[00m\] "

in questo modo viene sempre visualizzato il prompt della console in questo modo

ruby-1.9.2-p0@d7track ~/myapp (master) $

specificando sempre

ruby@gemset indirizzo (branch) $

guida originale

Update:

per avere un set di colori e alcune opzioni in più
https://github.com/jimeh/git-aware-prompt

git clone git://github.com/jimeh/git-aware-prompt.git ~/.bash

in questo modo si può usare in .bashrc

# from https://github.com/jimeh/git-aware-prompt

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export DOTBASH=~/.bash
source $DOTBASH/main.sh
export PS1="\[$txtblu\]\$(~/.rvm/bin/rvm-prompt) \[$txtgrn\]\w\[$txtcyn\]\$git_branch\[$txtrst\]\$ "
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "

martedì 12 luglio 2011

Rails 3 jquery tabs cookie memories

Usando JQuery ui tabs volevo mantenere la tab selezionata di volta in volta usando i cookie come mostrato qui

Per farlo ho incluso il plugin jquery.cookie.js, ma per non perdere gli indirizzi completi ho dovuto passare in application.js il path che altrimenti risultava troncato nel cookie


$(function() {
$( ".tabs" ).tabs({ cookie: {
expires: 1,
path: window.location.pathname
} });
});

martedì 10 maggio 2011

If i use a ldap configuration with

# config/ldap.yml
development:
base: ou=people,dc=test,dc=com
attribute: uid
group_base: ou=groups,dc=test,dc=com
required_groups:
- ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]

and I have my dn like

uid=gmgp,ou=developpers,ou=people,dc=test,dc=com

in the log the LDAPLogger write

LDAP: LDAP search: uid=gmgp
LDAP: Authorizing user uid=gmgp,ou=developpers,ou=people,dc=test,dc=com
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: User uid=gmgp,ou=people,dc=test,dc=com is not in group: cn=users,ou=groups,dc=test,dc=com

my simple workaround is to create a local attribute


#devise_ldap_authenticatable-0.4.6/lib/devise_ldap_authenticatable/ldap_adapter.rb

27 class LdapConnect
28
29 attr_reader :ldap, :login, :login_dn

54 def dn
55 DeviseLdapAuthenticatable::Logger.send("LDAP search: #{@attribute}=#{@login}")
56 filter = Net::LDAP::Filter.eq(@attribute.to_s, @login.to_s)
57 ldap_entry = nil
58 @ldap.search(:filter => filter) {|entry| ldap_entry = entry}
59 if ldap_entry.nil?
60 @ldap_auth_username_builder.call(@attribute,@login,@ldap)
61 else
62 @login_dn = ldap_entry.dn
63 end
64 end

84 def in_required_groups?
85 return true unless ::Devise.ldap_check_group_membership
86
...
99 admin_ldap.search(:base => group_name, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
100 unless entry[group_attribute].include? @login_dn
101 DeviseLdapAuthenticatable::Logger.send("User #{@login_dn} is not in group: #{group_name }")
102 return false
103 end
104 end
105 end

This workaround works even if it does not solve the underlying problem
I prepare a commit as it should if I find a moment of time