9:
10: <%= error_messages_for :post %>
11: <%= error_messages_for :topic %>[/code]
Problem wydawał by się prosty, wyglądało by na to że zmienna current_user nie jest ustawiona, niemiej jak w kontrolerze zaloguje sobie jej wartość to jest ok
def new
@topic = Topic.new
logger.info "kku_new_topic: #{current_user.inspect}"
end
natomiast w view nie jest
brakowało mi SavageBeast::AuthenticationSystem ale to nic nie zmienia
teraz mam:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
SavageBeast::AuthenticationSystem
...
...
i metody są zaimplementowane, o czym świadczyć może przypisanie wartości do zmiennej current_user w kontrolerze, co widać w logu …
pozdro i dzieki
krzysiek
Hej,
Przeczytałem chyba twojego posta przed zmianą
Dodałem helper_method :current_user do mojego kontrolera aplikacji
[code]# Filters added to this controller apply to all controllers in the application.
Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
SavageBeast::AuthenticationSystem
helper_method :current_user[/code]
niemniej z tego co widzę to helper_method zakłada że zwracanym typem jest string, bo w view wywala sie teraz tak
[code] NoMethodError in Topics#new
Showing vendor/plugins/savage_beast/app/views/topics/new.html.erb where line #9 raised:
undefined method `display_name’ for #String:0x6dd7330[/code]
a view jest zdefiniowane tak
Musisz zaimplementować te metody (dokładnie to są 3: display_name, admin? i metoda klasowa currently_online).
Z kolei Twoja metoda current_user ma zwracać obiekt modelu usera (prawdopodobnie klasa User). U Ciebie zwraca chyba String (tak przynajmniej wnioskuję po błędzie, helper_method niczego nie oczekuje, on po prostu udostępnia daną metodę kontrolera w widoku).
Btw, jeśli chcesz coś logować w widoku to spróbuj <%= debug zmienna %>.
[code]# Filters added to this controller apply to all controllers in the application.
Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
SavageBeast::AuthenticationSystem
helper_method :current_user
session :session_key => ‘_mpr_session_id’
init_gettext “mpr”
See ActionController::RequestForgeryProtection for details
Uncomment the :secret if you’re not using the cookie session store
def login_required
false
end
def current_user
@current_user ||= ((session[:family_id] && User.find_by_id(session[:family_id])) || 0)
logger.info "kku_current_user_666: #{@current_user.inspect}"
logger.info "kku_current_user_6661: #{@current_user.methods.inspect}"
end
def authorized?()
true
# in your code, redirect to an appropriate page if not an admin
end
def logged_in?
current_user != 0
end
def admin?
true
#logged_in? && current_user.admin?
end
end[/code]
i model Usera
[code]class User < ActiveRecord::Base
set_table_name “families”
include SavageBeast::UserInit
4 methods defined for savage beast plugin
def display_name
screen_name
end
def admin?
true
end
def currently_online
nil
end
def build_search_conditions(query)
query && [‘LOWER(screen_name) LIKE :q OR LOWER(screen_name) LIKE :q’, {:q => “%#{query}%”}]