I have an action in my controller #applications that renders a html page of my websites application page. When I specify the path for this action with the :pdf format it will render the page as a pdf (which works correctly).
I am writing another action #applications_print_version that needs to contain the rendered view from #applications plus some other pdfs (from a list of urls). Using combine_pdf I have been able to get the list of pdfs via urls working, but I can not get the #applications view to be added to the combined pdf in the #applications_print_version working.
Here is what I have so far.
def applications_print_version
html = render_to_string(action: :applications)
pdf = WickedPdf.new.pdf_from_string(html)
new_pdf = CombinePDF.new
new_pdf << CombinePDF.parse(pdf)
#List of pdfs I got from somewhere else
#pdf_attachments.each { |att| new_pdf << CombinePDF.parse( Net::HTTP.get( URI.parse( att.url ) ) ) }
send_data new_pdf.to_pdf, :disposition => 'inline', :type => "application/pdf"
end
This solution does have all the data, but the pdf variable has no styling. I can't seem to get this to work.
Thanks to a local community support I have managed to get it to work. There were a few things I needed to fix.
The layout that I was using to render #applications was using my standard pdf layout that I used for PDFKit. I duplicated the layout and replaced
<%= stylesheet_link_tag 'application' %>
with
<%= wicked_pdf_stylesheet_link_tag 'application' %>
One I did that I could render the #applications action with the layout the WickedPDF needed.
html = render_to_string(action: :applications, layout: 'wicked_pdf')
I ran into another issue. There is a known issue with WickedPDF https://github.com/mileszs/wicked_pdf/issues/470
So I had to remove any instances of #import "bootstrap" in my stylesheets which is not ideal, but I could not resolve the above issue.
Any now the #applications_print_version works correctly!
If anyone can do better, please let me know, I would like to know :)
Related
I have a component that includes a single Rich Text field. In the sublayout, the field is rendered as an Html.Editable with Glass so that it can be edited on the page in PageEditor. It looks like this:
public override void Initialize()
{
litBodyContent.Text = Html.Editable(GlassItem, item => item.Body);
}
<div style="min-height: 38px">
<asp:Literal runat="server" ID="litBodyContent" />
</div>
However, when I insert links using the Rich Text editor, when the page is rendered (in normal view after being published, not in page editor), the links are rendered with the item ID rather than the user friendly path, like this:
Go to another page
I am pretty sure that this is an issue with Glass. How can I keep the field editable in the Page Editor but make it render the link correctly?
You can check if you have proper attribute in the model.
If you have SitecoreFieldSettings.RichTextRaw attribute, it will NOT pass through render pipeline and returns the RAW HTML. Instead if you use Default (SitecoreFieldSettings.Default), rich text content will go through render pipeline and url will be in friendly format.
http://docs.glass.lu/html/d44739b2-5f0e-d862-f62c-86c50f0b262f.htm
Can you try to change it from using literal to use Editable() method directly, Something like:
<%= Editable(GlassItem, x => x.Body) %>
I think Initialize() is too soon in the page life cycle. Try moving it further along, like to Page_Load() or so.
I am having a login page for user generated by devise gem.where I removed the registerable from model for only login not for signup.I have also generated an admin which gives default login credentials for user in seed.rb file.I have done some css work in login page. next I have generated an employee page for further process for users.
Here my doubt is the styling part what I have done in login page is also coming in employee page. I dont want that so I wrote some condition in application.html.erb
<% unless user_signed_in? %>
<%= render 'layouts/heading' %>
<% end %>
The method is defined in application.controller.rb
def user_signed_in? %>
render :layouts => 'application'
end
I tried a lot by changing conditions but it is still displaying or showing errors.
You said that you're using "device gem", but since you're talking about authentication, I assume you mean "devise"?
The user_signed_in? method is a helper which should be provided automatically by devise, and you should be able to use it in your views. You shouldn't need to define it in the application controller.
You probably want to make sure you do "before_filter :authenticate_user!" in the relevant controller (you can use the ":only" option if you only want this to apply for certain methods).
It's difficult to give any more information because you haven't said what errors you are getting. I assume you're getting some kind of syntax error on the definition of the "user_signed_in?" method, since you have an invalid "%>"on the end of the line, which I guess you copied-and-pasted from an ERB file.
I am new to rails and am looking to do something very simple but don't know the correct syntax. I have 2 buttons one for creating a new page and one for creating a new post. Both a page and a post save in the same database table and are controlled through a boolean field called 'static'. A page therefore has a static value of 1 and a post 0. What I want to do is simply auto set this value in a form (and hide it) when I click new page or post. I imagined the link to create a new page would work something like this:
<%= link_to 'New Page', new_page_path(:static => "1") %>
This doesn't work so I tried to create a new_static page action and a new_post page action with correcting routing (for displaying only pages I created a show_static action used the following link_to and it works fine):
<%= link_to "Pages", show_static_pages_path(#pages), :method => :get %>
The problem is when I created the new_static page action it expects an id for some reason.
new_static_page GET /pages/:id/new_static(.:format) pages#new_static
I would prefer to not mess around with new actions and routing and simply set the value with link_to. Any tips would be greatly appreciated.
Using standard sitecore controls (Link and Text), you can embed a text field within a link in the following way:
<sc:Link runat="server" Field="LinkUrl" >
<sc:Text runat="server" Field="LinkText" />
</sc:Link>
That will give you the ability to edit the text of one field and link of another field.
I have tried to replicate this using Glass, but have been unsuccessful. Something like this would be good (It doesn't work):
<%= Editable( x => x.LinkUrl,new { Text = Editable(Model,q => q.LinkText,null)}) %>
Is there another way of sorting this out?
There are two options I see if I cannot do this using standard glass functionality:
Change the GlassHtml code
Use Two Fields
If you are using Razor use this:
#using (BeginRenderLink(x => x.Link, isEditable: true))
{
#Editable(x => x.Title);
}
If you are using WebForms:
<%using(BeginRenderLink(x=>x.Link){ %>
<%=Editable(x=>x.Title) %>
<% } %>
Mike
If you are using Glass version 3, then you can't use Editable on Link and Image fields.
Use RenderLink and RenderImage instead.
See here: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
The Editable method is the most basic method to use to make a field
editable and should be used with most fields that are page editable
except the Image field and General Link field
Currently I have a Note model which accepts nested attributes for an Attachments model, which uses Carrierwave. When adding a Note, I have a nested form to allow attaching file to the new Note:
Nested form field:
<%= f.file_field :image, multiple: true, name: "attachment[file]" %>
I am using the Cocoon gem to add the nested field. While I can easily let them add multiple file upload fields with Cocoon, and add multiple attachments that way, I only want to load one file upload field, and let them use multi select to select multiple images.
When I do this, the file upload field says '2 Images' next to it. However, upon form submission, only one file is listed under 'attachments_attributes'. I need all of the attachments to submit at once as the Note has not yet been saved.
What is the proper way to accomplish this? I am aware of the Railscast on this topic however it did not seem to address my particular scenario.
Any help is appreciated.
Just append [] to your params
<%= f.file_field :image, multiple: true, name: "attachment[file][]" %>