When moving a views to a new directory, what changes must I make for them to work

70 Views Asked by At

To be specific I simply created a subdirectory in the one they were currently contained in and I am now getting

Missing template users/index, application/index with {:locale=>[:en]....

I assume I need to make a simple change elsewhere so rails knows where to find the views however I have not been able to figure it out.

Edit: to elaborate further, its not all of them, just a specific group that I wanted to organize.

Edit2: to elaborate even further... the path to these views is users_path, and I need to somehow update it so that it knows where to find the views. Would this be in the routes?

Edit3:

in the users_controller.rb i tried:

render view/index.html.erb

and got the error

undefined local variable or method `view'

i also tried

render :partial => "view/index.html.erb"

and got the error

undefined method `render'

Edit4:

class UsersController < ApplicationController
  before_filter :authenticate_user!

  def index
    @users = User.all
  end

  def show
    @user = User.find(params[:id])
    unless @user == current_user
      redirect_to :back, :alert => "Access denied."
    end
  end
end

Edit5:

<div class="container">
    <h3>Users</h3>
    <table>
        <tbody>
        <% @users.each do |user| %>
            <tr>
                <%= render user %>
            </tr>
        <% end %>
        </tbody>
    </table>
</div>
1

There are 1 best solutions below

12
On BEST ANSWER

Try in the appropriate place of your controller: e.g., render 'subfolder/view_file'. If you don't specify this in the controller, Rails will look for the default location for the view (so you need to specify this if the view is not in the default location). So if it's the index view that you've relocated, you need to specify generally at the end of the index method in the controller, which view it needs to render: render 'subfolder/index'.

If the relocated view is a partial, you would need to specify the path to this partial there where you call for the partial.

It's not in the routes where you need to make adjustments: in routes you specify which controller method to execute as a user visits a certain url of your website.