you-rick
you-rick

Reputation: 185

Ruby on Rails views names dependences

May be my question it's a little weird for RoR developers, but i'm new in Ruby on Rails, and i only discover this world now - there is some dependencies in views names and definitions in controller?

If i have, for example, view called "parse-public-profile.html.erb" , should i add in controller definition with exactly this name? i mean "def parse-public-profile ... end"

I know, that this is basic, but simply i try to understand how controller knows, what views i have now; what i should change, if i will add/change-name of view, or how to define view, if in my "views" folder, i have another folder, for ex. "clients"

Thanks!

Upvotes: 0

Views: 178

Answers (2)

Jason Noble
Jason Noble

Reputation: 3766

You can also use:

def index
  render :template => "users/parse-public-profile"
end

The :template over rides the default file that Rails would have rendered.

For more info, see the Rails Guide on Layouts and Rendering at http://guides.rubyonrails.org/layouts_and_rendering.html.

Upvotes: 0

Novae
Novae

Reputation: 1171

Rails follows REST this means methods as index, show, edit, update, destroy etc. are very common in an Rails controller. When you have a custom action(method) however on your controller Rails will look for the corresponding view file, so for example:

class UsersController < ApplicationController
  def another_action
  end
end

will try to render: app/views/users/another_action.html.erb

There is also the concept of partials which are normally called within a view file f.e. in users/index.html.erb

<% render :partial => 'form' %> 

will try to render: app/views/users/_form.html.erb (note the _) An in depth explanation can be found in the Rails guides

Upvotes: 2

Related Questions