Michael Lombardo Michael Lombardo - 6 months ago 9
HTML Question

My index view doesnt exist on rake routes

I understand sorta why my

reviser
index page isn't showing up, but I don't know how to go about it. In my rake routes there is no reviser#index even though I made a
def index
on my controller. I have a
has_one
relation between a
user
and
reviser
, as a
user
can apply to become a
reviser
. This is the url to show a specific reviser
http://localhost:3000/users/15/reviser
however I also want there to be a way to see your profile as if you are the current user. That's why I set up an index. So I want a url that shows only my current user as a reviser based off my index ex.
http://localhost:3000/users/reviser
or
http://localhost:3000/reviser
how might I be able to make my index page show up as current user page. To sum it up: my ReviserController index isn't showing up in routes. Want url to be http://localhost:3000/reviser for
current_user
. Thank you!

ReviserController:

class RevisersController < ApplicationController

before_action :set_reviser, only: [:show, :edit, :update]
before_action :authenticate_user!, except: [:show]

def index
@reviser = current_user.reviser
end

def show

end

def new
@reviser = current_user.build_reviser(params[:reviser])
@user = User.find(params[:user_id])
end

def create
@reviser = current_user.reviser.build(reviser_params)

if @reviser.save
redirect_to @reviser,notice: "saved...."
else
render :new
end
end

def edit
set_reviser
end

def update
set_reviser
if @reviser.update(reviser_params)
redirect_to @reviser,notice: "updated.."
else
render :edit
end
end

private
def set_reviser
@reviser = current_user.reviser
end

def reviser_params
params.require(:reviser).permit(:description, :average_start, :average_end, :max_pages, :price_per, :active)
end
end


index.html


<div class="row">
<div class="col-md-3">
<ul class="sidebar-list">
<li class="sidebar-item"><%= link_to "Your Reviser Profile", reviser_path, class: "sidebar-list active" %></li>
<li class="sidebar-item"><%= link_to "Your Essays", reviser_path, class: "sidebar-list active" %></li>
</ul>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
Reviser
</div>
<div class="panel-body">
<% @reviser.each do |reviser| %>
<div class="row">
<div class="col-md-2">
<%= link_to image_tag(current_user.avatar.url(:medium), class:'img-responsive'), user_path(user) %>

</div>
</div>
<% end %>
</div>
</div>
</div>
</div>





routes.rb:

resources :users, only: [:index, :show] do
resource :reviser
end


Rake routes: (index for reviser doesn't show up!!!)


  1. user_reviser POST /users/:user_id/reviser(.:format) revisers#create

  2. new_user_reviser GET /users/:user_id/reviser/new(.:format) revisers#new

  3. edit_user_reviser GET /users/:user_id/reviser/edit(.:format) revisers#edit

  4. GET /users/:user_id/reviser(.:format) revisers#show

  5. PATCH /users/:user_id/reviser(.:format) revisers#update

  6. PUT /users/:user_id/reviser(.:format) revisers#update

  7. DELETE /users/:user_id/reviser(.:format) revisers#destroy

  8. users GET /users(.:format) users#index

  9. user GET /users/:id(.:format) users#show


Answer

As you can see in the rails route guide singular resource like the one you are using does not add an index method.

You should modify your routes.rb file to

resources :users, only: [:index, :show] do 
    resources :revisers
end
Comments