2008年12月9日火曜日

どうよ? じゃねえよwww

いきなりレイアウト崩れてんじゃねぇよwww->blogger.com
ホンキ、使えねえなwww

また引っ越しちゃうぞwwwww


で。
メソッド、全然足りてねえでやんのwww
lib/authentication_system.rb
+    def permission_denied
+      respond_to do |format|
+        format.html do
+          #Put your domain name here ex. http://www.example.com
+          domain_name = "http://localhost:3000"
+          http_referer = session[:refer_to]
+          if http_referer.nil?
+            store_referer
+            http_referer = ( session[:refer_to] || domain_name )
+          end
+          flash[:error] = "You don't have permission to complete that action."
+          #The [0..20] represents the 21 characters in http://localhost:3000
+          #You have to set that to the number of characters in your domain name
+          if http_referer[0..20] != domain_name  
+            session[:refer_to] = nil
+            redirect_to root_path
+          else
+            redirect_to_referer_or_default(root_path)  
+          end
+        end
+        format.xml do
+          headers["Status"]           = "Unauthorized"
+          headers["WWW-Authenticate"] = %(Basic realm="Web Password")
+          render :text => "You don't have permission to complete this action.", :status => '401 Unauthorized'
+        end
+      end
+    end

+    def store_referer
+      session[:refer_to] = request.env["HTTP_REFERER"]
+    end

+    def redirect_to_referer_or_default(default)
+      redirect_to(session[:refer_to] || default)
+      session[:refer_to] = nil
+    end

ん。
んで、http://localhost:3000/usersに行ってみると...

NoMethodError in Users#index
Showing app/views/users/_user.html.erb where line #4 raised:

undefined method `enabled' for #

!?
なんだよ? "enabled"って?
で、見てみたら、どうも、メソッドではなくって、スキーマくさい。
どうも、今のバージョンのrestrul_authentication --aasmだと、enabledじゃなくって、statusになってるっぽい。
んじゃあ、ってんで、書き換えよう。
app/views/users/_user.html.erb

-  <td><%= user.enabled ? 'yes' : 'no' %>
+  <td><%= user.state == "active"  ? 'yes' : 'no' %>

-      <% if user.enabled %>
+      <% if user.state == "active" %>
ん。動いた。
動いたことは動いたんだけど、ブラウザで表示して、「enable」のリンクをクリックしても、何の変化もなし。

んー...
っていうか、enableなんてメソッド、作ってないわwww
じゃあ、移植しましょう、ってことで。
でも、メソッド名は変えるよ。それっぽく。
app/controllers/users_controller.rb
+  def forcible_activate
+    @user = User.find(params[:id])
+    if @user.update_attribute(:state, "active")
+      flash[:notice] = "User activated"
+    else
+      flash[:error] = "There was a problem activating this user."
+    end
+      redirect_to :action => 'index'
+  end
あと、administrator_role_requiredの:enabelも書き換えなきゃな。
-before_filter :administrator_role_required, :only => [:index, :destroy, :enable]
+before_filter :administrator_role_required, :only => [:index, :destroy, :forcible_activate]

んで、ルーティングも変更。
config/routes.rb
+  map.forcible_activate '/forcible_activate/:id', :controller => "users", :action => "forcible_activate"

んで、viewも変更。
app/views/users/_user.html.erb
-  <td><%= user.enabled ? 'yes' : 'no' %>
-    <% unless user == current_user %>
-      <% if user.enabled %>
-        <%= link_to('disable', user_path(user.id), :method => :delete) %>
-      <% else %>
-        <%= link_to('enable', enable_user_path(user.id), :method => :put) %>
-      <% end %>
-    <% end %>
-  </td>

+  <td>
+    <%= h user.state %>
+    <% unless user == current_user %>
+      <% if user.state == "active" %>
+        <%= link_to('inactivate', user_path(user.id), :method=> :delete) %>
+      <% else %>
+        <%= link_to('activate', forcible_activate_path(user.id), :method => :put) %>
+      <% end %>
+    <% end %>
+  </td>
よし。これで、ユーザ管理画面チックなものが出来たよね?:-)

0 件のコメント: