Guest User

Untitled

a guest
Jul 16th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. ## Error
  2.  
  3. ActionController::RoutingError in Users#index
  4.  
  5. Showing users/index.html.erb where line #8 raised:
  6.  
  7. edit_company_user_url failed to generate from {:controller=>"users", :action=>"edit", :company_id=>#<User id: 7, username: "test456", hashed_password: "63aceb369de62e70ce6789dab766593b1f51c7d9", salt: "-6152955080.83472661421613", created_at: "2009-10-26 22:18:29", updated_at: "2009-10-26 22:18:29", role: "Corporate", company_id: 1>}, expected: {:controller=>"users", :action=>"edit"}, diff: {:company_id=>#<User id: 7, username: "test456", hashed_password: "63aceb369de62e70ce6789dab766593b1f51c7d9", salt: "-6152955080.83472661421613", created_at: "2009-10-26 22:18:29", updated_at: "2009-10-26 22:18:29", role: "Corporate", company_id: 1>}
  8.  
  9. Extracted source (around line #8):
  10.  
  11. 5: <% for user in @users %>
  12. 6: <div class="item">
  13. 7: <span class="itemName"><%=h user.username %></span>
  14. 8: <span class="itemActions"><%= link_to 'Edit', edit_company_user_path(user) %>
  15. 9: <%= link_to 'Destroy', company_user_path(user), :confirm => 'Are you sure?', :method => :delete %></span>
  16. 10: </div>
  17. 11: <% end %>
  18.  
  19.  
  20.  
  21. ## Routes
  22.  
  23. map.resources :companies, :shallow => true do |companies|
  24. companies.resources :users
  25. companies.resources :regions do |regions|
  26. regions.resources :locations do |locations|
  27. locations.resources :sales
  28. end
  29. end
  30. end
  31.  
  32.  
  33.  
  34. ## Users Controller
  35.  
  36. class UsersController < ApplicationController
  37. # GET /users
  38. # GET /users.xml
  39.  
  40. before_filter :load_user_index, :only => ['index' ]
  41. access_control do
  42. allow :admin
  43. end
  44.  
  45. before_filter :load_user, :only => ['show', 'destroy' ]
  46. access_control do
  47. allow :admin
  48. end
  49.  
  50. before_filter :load_user_manage, :only => ['edit', 'create', 'new', 'update', 'destroy' ]
  51. access_control do
  52. allow :admin
  53. end
  54.  
  55. def index
  56.  
  57. respond_to do |format|
  58. format.html # index.html.erb
  59. format.xml { render :xml => @users }
  60. end
  61. end
  62.  
  63.  
  64. # GET /users/1
  65. # GET /users/1.xml
  66. def show
  67.  
  68. respond_to do |format|
  69. format.html # show.html.erb
  70. format.xml { render :xml => @user }
  71. end
  72. end
  73.  
  74. # GET /users/new
  75. # GET /users/new.xml
  76. def new
  77.  
  78. respond_to do |format|
  79. format.html # new.html.erb
  80. format.xml { render :xml => @user }
  81. end
  82. end
  83.  
  84. # GET /users/1/edit
  85. def edit
  86.  
  87. end
  88.  
  89. # POST /users
  90. # POST /users.xml
  91. def create
  92.  
  93. respond_to do |format|
  94.  
  95. if @user.role == "Admin"
  96. @user.has_role! :admin
  97. end
  98.  
  99. if @user.role == "Corporate"
  100. @user.has_role! :corporate
  101. end
  102.  
  103. if @user.role == "Regional"
  104. @user.has_role!(:regional, @company)
  105. end
  106.  
  107. if @user.save
  108. flash[:notice] = "User #{@user.username} was successfully created."
  109. format.html { redirect_to(:action =>'index') }
  110. format.xml { render :xml => @user, :status => :created, :location => @user }
  111. else
  112. format.html { render :action => "new" }
  113. format.xml { render :xml => @user.errors,
  114. :status => :unprocessable_entity }
  115. end
  116. end
  117. end
  118.  
  119. # PUT /users/1
  120. # PUT /users/1.xml
  121. def update
  122.  
  123. respond_to do |format|
  124. if @user.update_attributes(params[:user])
  125. flash[:notice] = 'User #{@user.username} was successfully updated.'
  126. format.html { redirect_to(:action =>'index') }
  127. format.xml { head :ok }
  128. else
  129. format.html { render :action => "edit" }
  130. format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
  131. end
  132. end
  133. end
  134.  
  135. # DELETE /users/1
  136. # DELETE /users/1.xml
  137. def destroy
  138. begin
  139. @user.destroy
  140. flash[:notice] = "User #{@user.username} deleted"
  141. rescue Exception => e
  142. flash[:notice] = e.message
  143. end
  144.  
  145. respond_to do |format|
  146. format.html { redirect_to(users_url) }
  147. format.xml { head :ok }
  148. end
  149. end
  150.  
  151. private
  152.  
  153. def load_user
  154. @company = Company.find(params[:company_id])
  155. @user = User.find(params[:id])
  156. end
  157.  
  158. def load_user_index
  159. @company = Company.find(params[:company_id])
  160. @users = @company.users
  161. end
  162.  
  163. def load_user_manage
  164. @company = Company.find(params[:company_id])
  165. @user = @company.users.build(params[:user])
  166. end
  167.  
  168. end
Add Comment
Please, Sign In to add comment