Skip to content

Instantly share code, notes, and snippets.

@regedarek
Created January 19, 2012 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regedarek/1643261 to your computer and use it in GitHub Desktop.
Save regedarek/1643261 to your computer and use it in GitHub Desktop.
Chcę aby po kliknięciu w Fast Verification, a następnie Verify aby redirect_to było do ostatniego niezweryfikowanego ogłoszenia.
#verifications/index.haml
- unless @ads.unverified_ads.empty?
= link_to "Szybka Weryfikacja", fast_verify_info_verification_path(@ads.unverified_ads.last), :method => :put
= link_to "Ogłoszenia do zweryfikowania", verifications_path(:scope => "unverified_ads")
= @ads.unverified_ads.count
= link_to "Normal Verify", verify_info_verification_path(ad), :method => :put
#verifications/verify_info.haml
= link_to "Verify", verify_verification_path(@ad)
#verifications/fast_verify_info.haml
= link_to "Weryfikuj", fast_verify_verification_path(Ad.unverified_ads.last), :method => :put
#verification_controller.rb
class VerificationsController < ApplicationController
before_filter :require_login
before_filter :load_ad, :except => [:index]
before_filter :verify_ad, :only => [:fast_verify, :verify]
def index
@ads = Ad.with_some_scope(params[:scope], params[:email])
end
def verify_info
end
def fast_verify_info
end
def fast_verify
redirect_to (Ad.unverified_ads.blank? ? verifications_path : fast_verify_info_verification_path(Ad.unverified_ads.last))
end
def verify
redirect_to verifications_path
end
private
def load_ad
@ad = Ad.find(params[:id])
end
def verify_ad
@ad.verify!(current_user.id)
end
end
@andrzejkrzywda
Copy link

  1. w widoku odwolanie do modelu to shit (Ad...last).
  2. @ad.update_attribute :verification_date, Time.now wygladaloby lepiej jako @ad.verify! i implementacja w modelu.

@mlomnicki
Copy link

params zawiera to co przychodzi w requescie. Chociaż jest to możliwe to nigdy nie powinno się tego nadpisywać

@regedarek
Copy link
Author

@andrzejkrzywda oczywiście zgadzam się z twoimi punktami :) Poprawiam...

@paneq
Copy link

paneq commented Jan 20, 2012

Ad.unverified_ads.size == 0

Wyciągnąć jako metodę do modelu

@paneq
Copy link

paneq commented Jan 20, 2012

Ja tam często lubie mieć głupie kontrolery i jeśli jest to obojętne dla security to wysyłać im info gdzie ma pójść redirect zamiast w nich zaszywać całą logikę

redirect_to params[:redirect_to] || domyslny_path

Jak jakiś widok potrzebuje to samo zrobić ale wrócić w inne miejsce, bardziej sensowne z punktu widzenia interakcji użytkownika to używa tego w stylu

link_to "Weryfikacja", verify_info_verification_path(ad, redirect_to: request.path) # przykładowo albo zamiast request.path to costam_costam_path(ad)

@regedarek
Copy link
Author

23:56 < AndrzejKrzy> | kontroler moze przekazac @last_unverified_ad do widoku, a pobrac go poprzez @last_unverified_ad = Ad.last_unverified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment