Rails 3 render layout except for root_url - ruby-on-rails-3

I want to have a different layout for the home page (root_url) than the other pages in my web app. I would like to be able to use <%= render 'layouts/pages' %> for pages that are not the home page. How do I go about doing this?

Majority
The best way to do this is to name the layout for the majority of your app layouts/application - this way, Rails will automatically assume this layout for that majority without you needing to do anything else.
Home
For your home page, you can add this line to the bottom of your controller action:
render :layout => "home"
This will tell Rails not to use application, but instead to point to your home/root page's layout, which in this case would be located at layouts/home.

Related

Ruby on Rails. Devise. Registration form in yield

I application.html.erb I add <%= yield %>. I want to show registration page (/users/sign_up) with header and footer in application.html.erb. As I understand contant from /device/registration/new.html.erb must contain in yield, but I get registration page withot templates(header and footer).
How I could show registration form in yiled?
I use RoR 3.2.12. Sorry for my English. Thanks.
If you get the registration page without the layout, then chances are you have a :layout => false triggered somewhere upstream.

Rendering an HTML file in rails

I am using CarrierWave to upload static HTML templates to certain user profiles on my webpage.
I am trying to render the HTML file on the user's home page once they log in. The Path for the HTML file after uploading is:
/uploads/profile/curation/8/User_Content.html
I'm new to rails and I thought I'd just be able to
<%= render /uploads/profile/curation/8/User_Content.html %>
to get the html to render, but I guess that only works for partials, which this is not.
Any advice?
You can use render_to_string. Please have a look over here. http://russbrooks.com/2009/11/18/embed-a-static-hmtl-page-in-a-rails-view
In your controller you can redirect to the page you want:
redirect_to "/uploads/profile/curation/8/User_Content.html"

Render layout without a controller

I'm writing a Rails 3.2 app with backbone, and since I only need rails to render one page, I have no need for a controller to back the index page.
Is there a way to render the layout (application.html.erb) without a controller? I imagine it would be a configuration in the routes.rb file?
My first thought was to move it to index.html in the /public directory, but I need to take advantage of erb for javascript includes and CSRF helpers, etc.
I get that you don't need the controller to do anything, but Rails is "opinionated" software; it expects a controller and a view, because that is the way it was designed, and trying to work around that is going to give you a lot of trouble.
Just
create an empty controller class in /app/controllers/main_controller.rb
create an empty view file /app/views/main/index.html.erb
set up a route like :root => 'main#index'
Easy peasy.

How do I properly setup a custom page layout - RefineryCMS 2.0.6

I have followed the instructions found on the Guides for building a custom layout:
NOTE: The portfolio is an engine of my own, not the refinerycms-portfolio.
config.layout_template_whitelist = ["application","portfolio"]
config.use_layout_templates = true
Created a portfolio.html.erb under app/views/layouts and copied everything from the application.html.erb except for the <header> section: I do not want the menu and logo shown in this layout, but all the rest
I can now see the layouts in the back end.
If I choose my portfolio page and press preview, the layout renders without the menu
However, if I go directly to /portfolios, the 'application' layout renders and not the 'portfolio'
Any ideas please?
Thank you...
Well, it seems that the namespacing introduced in the latest RefineryCMS versions prevents the layout to be picked up automatically, thus you need to manually instruct the Controller to pick up the layout in question. To this case I had to add:
render :layout => 'layouts/portfolio'
in my portfolios#index action.
Hope this helps...

Render a custom page in ActiveAdmin using Rails 3

I have seen the following page:
http://activeadmin.info/docs/9-custom-pages.html
It doesn´t have a lot of information on how to create a custom page.
What I need to do is to add a custom action to the index of an entity that redirects me to another page i.e. /admin/mycustompage . I want to render my new page from a partial. It has to look similar to a view or edit page (with a breadcrumb and the layout).
The example in the docs is too simple:
ActiveAdmin.register_page "My Page" do
content do
para "Hello World"
end
end
How can I render a partial within the content?
How can I render the breadcrumb?
How is the url for this new page specified?
Thanks.
Sample page, rendering /app/views/admin/password/_index.html.haml partial:
ActiveAdmin.register_page "Password" do
menu label: I18n.t("menu.change_password")
content do
render "index"
end
end
Default url for this page is /admin/password (you can check it by calling 'rake routes').
If your page title contains spaces, you have to use aa version from github, because it was impossible until this commit - https://github.com/gregbell/active_admin/commit/30b19c86eef3c504fe71c2e39e072620169b80c2