1

I am fairly new to rails and had a question.

I am wanting to direct my controller to point to the html.erb view i created.

I have tried various versions of:

def index
  render :"viewName"
end

def index
  render :viewName
end

def index
  render : "viewName.html.erb"
end

My router is set as such:

Rails.application.routes.draw do
  root 'application#index'
end
1
  • Your root file says my root page on my website is the view that is rendered by the index action of Controller Application. Then if you have an index.html.erb file in your /app/views/application/index.html.erb folder. And your Application controller shows an index action (even empty) def index end then the view should be shown. (though Application controller is usually empty because it intuitively should do Nothing, there is no logic showing the index of an application. If you had a User model and controller then it makes sense to have an User#index which should return a list of users) Commented Jul 2, 2017 at 13:01

2 Answers 2

1

You just need to follow the convention, if you're pointing it to the controller: Application, action: Index, then you need an "application" folder in your views, and a "index.html.erb" inside this application folder and you don't need to call any render inside the action.

So in this case create the following folder

/app/views/application

And inside it place your:

index.html.erb

On your application_controller.rb

def index; end

I wouldn't use application controller though...

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to render a partial then

render partial: 'some_view'

or

render 'some_view'

this will look for a file _some_view.html.erb

If you want to render some template then

render template: 'template_name'

this will look for template_name.html.erb

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.