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
Get the name of the database column storing your users’ names (let’s say it’s ‘name’).
In config/routes.rb add, somewhere above the default route:
match 'users/:name', :controller => 'users', :action => 'show'
Now, in users_controller, find def show and change it to:
@user = User.find_by_name(params[:name])
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
Rails Console: Reload! Not Reflecting Changes in Model Files? What Could Be Possible Reason
Ruby on Rails Best Practices - Big Controller VS Small Controller
Why Are Methods in Ruby Documentation Preceded by a Hash Sign
How to Calculate the Day of the Week of a Date in Ruby
Validation Failed: Upload File Has an Extension That Does Not Match Its Contents
Gem Eventmachine Fatal Error: 'Openssl/Ssl.H' File Not Found
Rvm 'Not Found' After Successful Usage and a Few Days Later
Ruby:Difference Between Instance and Local Variables in Ruby
What Is the "Right" Way to Iterate Through an Array in Ruby
Ruby on Rails Console Is Hanging When Loading
Invalid Active Developer Path on MAC Os X After Installing Ruby
What Evaluates to False in Ruby
When to Use Each Method of Launching a Subprocess in Ruby
Running a Command from Ruby Displaying and Capturing the Output
Rails Installation Failed on Ubuntu With "Cannot Load Such File - Mkmf"