How to Change the Default Path of View Files in a Rails 3 Controller

How to change the default path of view files in a Rails 3 controller?

If there's no built-in method for this, perhaps you can override render for that controller?

class MyController < ApplicationController
# actions ..

private

def render(*args)
options = args.extract_options!
options[:template] = "/mycustomfolder/#{params[:action]}"
super(*(args << options))
end
end

Not sure how well this works out in practice, or if it works at all.

change default load path for devise views and controller

It is all Here

Don't copy manually, use the generator

rails generate devise:views

All needed views will be generated under app/views/devise

As for the controllers, create them under app/controllers

class RegistrationsController < Devise::RegistrationsController

end

or

class SessionsController < Devise::SessionsController

end

and change routes.rb to point them:

devise_for :admins, :controllers => { :sessions => "<YOUR_SESSION_CONTROLLER>", :registrations =>  "<YOUR_REGISTRATION_CONTROLLER>"}

Change directory for views in a controller

Essentially the answer is no. There are workarounds like the one pointed to by odin, but they are just workarounds and they tend to be ugly.

Setting default page for Controller in Rails

in your routes.rb add line:

get '/greet' => 'greet#welcome'

you must also in folder view create folder greet and in this folder you have to create file welcome.html.erb

Rails use default layout for controller

You need get into this guide Layouts and Rendering in Rails

And if I understand you right, you whant to do somethisng like

...
<div class='my_div'>
<%= yeild %>
</div>
...

Changing the default rails route

  1. Get the name of the database column storing your users’ names (let’s say it’s ‘name’).

  2. In config/routes.rb add, somewhere above the default route:

    match 'users/:name', :controller => 'users', :action => 'show'
  3. Now, in users_controller, find def show and change it to:

    @user = User.find_by_name(params[:name])
  4. Lastly, all the id-based urls pointing to your users need to be updated to reflect the name-based change. Like the one your Users index.html.erb file.

    link_to @user.name, 'users/#{@user.name}'

How can I change the default layout directory?

The path is relative to layouts folder. Try:

layout '../utilisation/layouts/application' # without .html.erb is fine


Related Topics



Leave a reply



Submit