daniel
daniel

Reputation: 11

Having trouble displaying my html created view with my controller

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

Upvotes: 1

Views: 51

Answers (2)

Ganesh
Ganesh

Reputation: 2004

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

Upvotes: 0

m3characters
m3characters

Reputation: 2290

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...

Upvotes: 1

Related Questions