Render a custom page in ActiveAdmin using Rails 3 - ruby-on-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

Related

How to render full RazorPage to string?

I tried to use the solution from https://stackoverflow.com/a/54043063/234954, to render a page as a string (so I can turn it into a PDF), but that only gets me the main view, it doesn't get the layout associated with the page (and so it is missing the style sheets and some header/footers).
How can I render the full page as a string, and not just the partial view?
I used this article code in a recent project to render html to feed into PDF generation.
I used templates in the Views folder so not razor pages.
It works with Layouts and partials in templates.
https://ppolyzos.com/2016/09/09/asp-net-core-render-view-to-string/
I found that I could get what I wanted (the whole page) by making two changes to the answer I was looking at:
var view = new RazorView(_razorViewEngine,
_activator,
new List<IRazorPage>(),
page,
HtmlEncoder.Default,
new DiagnosticListener("ViewRenderService"));
changed to :
var view = new RazorView(_razorViewEngine,
_activator,
pageModel.PageContext.ViewStartFactories.Select(v => v()).ToList(),
page,
HtmlEncoder.Default,
new DiagnosticListener("ViewRenderService"));
and
await page.ExecuteAsync();
to
await view.RenderAsync(viewContext);
Note that if the viewstart pages aren't included in the view, then rendering the view produces the same as executing the page.

Carousel is null on web page in Stencil theme

When creating a custom Page Template for use as Home Page, "Display as Home Page
Yes, display this page as the home page of my store " the "carousel" data element is null, making it impossible to use stencil CLI. Is there a work-around for this?
You'll want to be sure to include carousel: true in the front matter for your page.html template. The custom template you create will pick up its context from page.html. Hope that helps!

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"

Clicking a link using rspec and capybara doesn't load the page

In Rails 3.2 I'm using rspec (2.11.0) and capybara 1.1.2 (and have not installed webrat) and it's doing something strange when I click a link on my web page.
I'm trying to click on link on my home page to go to another page. Below is the basic rspec test.
it "should go to agents page" do
visit 'home'
#puts page.body
#links = page.all('a')
#links.each do |l|
# puts l.text
#end
page.find_by_id('menu_agents').click
puts page.body
#<various content asserts on page currently commented out>
end
I basically go to a page, grab a link and click
The link exists. As you can see from the commented out statements I've confirmed by looking at the page in the console and also looking at the list of links. I've tried clicking not only with the link above, but also using click_link and referencing the id. Looking at both the code and the html of the page when I run the code I see the id of the element.
In all cases I get the following result:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
When running the software with rails s clicking the link does load the correct page. Likewise when I visit the home page in the test it loads correctly as well, since when I print the body to the console I see the right html.
It seems like something is going wrong with the page load when I click the link and the page load has some type of failure (although the test itself does not fail). Any ideas?
Please try this:
Page load will take some time. Use sleep function. It makes some time to wait.
Then use page.find("#menu_agents").click instead of page.find_by_id('menu_agents').click
Verify menu_agents id name is not present any other places in result page.
Note: make sure menu_agents id is unique.
it "should go to agents page" do
visit 'home'
sleep 5
page.find("#menu_agents").click
puts page.body
#<various content asserts on page currently commented out
end

Rails 3 render layout except for root_url

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.