Skip to content
Browse files

Refactoring of controllers to improve readability

  • Loading branch information...
1 parent a6ea859 commit 48eb4ce4aecea7a79be4e7d49b21766f728ff3d9 @vinibaggio committed Dec 11, 2009
View
6 app/controllers/users/filters.rb
@@ -3,13 +3,19 @@ module Users::Filters
def acts_as_user(options={})
before_filter :find_user_from_session, :find_requested_user
+ belongs_to :user, :finder => :find_by_username!
+ defaults options.reverse_merge(:route_prefix => '')
+
include ControllerMethods
end
def acts_as_current_user(options={})
# fetch the user first, then verify if the user can access
prepend_before_filter :find_user_from_session, :current_user_only, :find_requested_user
+ belongs_to :user, :finder => :find_by_username!
+ defaults options.reverse_merge(:route_prefix => '')
+
include ControllerMethods
end
View
7 app/controllers/users/shared_lists_controller.rb
@@ -1,8 +1,11 @@
class Users::SharedListsController < InheritedResources::Base
- belongs_to :user, :finder => :find_by_username!
actions :only => [:index]
- acts_as_user
+ acts_as_user(:collection_name => 'task_lists')
+
+ def collection
+ end_of_association_chain.shared
+ end
end
View
1 app/controllers/users/task_lists_controller.rb
@@ -1,6 +1,5 @@
class Users::TaskListsController < InheritedResources::Base
acts_as_current_user
- belongs_to :user, :finder => :find_by_username!
actions :all, :except => [:update]
def new
View
6 app/views/users/shared_lists/index.html.erb
@@ -1,10 +1,10 @@
-<h1>Displaying <%= @user.username %>'s shared lists</h1>
+<h1>Displaying <%# @requested_user.username %>'s shared lists</h1>
<p>
-<% if @shared_lists.blank? %>
+<% if collection.blank? %>
User has no shared lists.
<% else -%>
- <% @shared_lists.each do |task_list| -%>
+ <% collection.each do |task_list| -%>
<%= render :partial => 'shared/task_list' , :locals => {:task_list => task_list} %>
<% end -%>
<% end -%>
View
2 app/views/users/task_lists/index.html.erb
@@ -5,7 +5,7 @@
There are no task lists.
<% else -%>
<% collection.each do |task_list| -%>
- <%= link_to task_list.title, user_task_list_path(@current_user, task_list)%>
+ <%= link_to task_list.title, user_task_list_path(@current_user, task_list)%><br/>
<% end -%>
<% end if -%>
</p>
View
2 app/views/users/task_lists/new.html.erb
@@ -1,6 +1,6 @@
<h1>New task list</h1>
-<% form_for @task_list, :url => collection_path do |f| %>
+<% form_for @task_list, :url => user_task_lists_path(@current_user) do |f| %>
<fieldset>
<legend>Task list information</legend>
<div class="task_list">

0 comments on commit 48eb4ce

Please sign in to comment.
Something went wrong with that request. Please try again.