Not sure what your actual needs are but you can pass instance variables
into the PDF writer just as you can in an normal .erb template/
So anything that you would have done in a normal view file can be done
in the pdf view files.
Try to create it as a standalone first and then integrate it into the
actionlinks of AS.
so I have a print function in my controller:
def some_page
@form = Form.find_by_user_id(current_user.id)
@students = Student.find_by_owner(current_user.id)
end
Inside the page I have several structures typical of a template:
You can call partials:
render :partial=>'hdr_c3', :format => 'pdf', :locals=>{:p_user => @user}
render :partial=>'students', :format => 'pdf', :locals=>{:p_students =>
@students}
You can have loops to access the instance variables defined in the
controller
@students.each do |b|
a_numbers += b.first_name + ": " +
number_to_currency(@form[Form::A_INDEX[n]]) + "\n" unless b.klass_id.nil?
end
You have access to the params[:id] (and everything else in params) to
use in your code
To link to a pdf I use:
<%= link_to(@pdficon+"Print all my personalized Forms", {:action =>
'package', :id => current_user.id, :format => 'pdf'}, :popup =>
Konfig::POPTIONS2) %>
Hope this helps you
/S
adc wrote:
> I try Prawn and Prawn_to, but i have some problems with generate
> file .pdf.
>
> I want to create a new page (print.pdf) and pass the data of record
> through an action like show, delete etc...
>
> How can I make this operation?
>
> Thanks for all
>
> ADC
>
> On 23 Giu, 18:54, Soren Christensen <[email protected]> wrote:
>
>> Rails is trying to render the template for the function. So you can move
>> some of the text into the template.
>>
>> I would suggest that you also add the parameter :format => "pdf" to the
>> action link.
>>
>> It changes the template naming to be <method>.pdf.erb
>>
>> You can also take a look at Prawn and Prawnto. There is a great
>> railscasts.com episode on those.
>>
>> /S
>>
>> adcwrote:
>>
>>> I created an action link with
>>>
>>> 1. config.action_links.add 'generate_pdf', :label=>"Stampa
>>> PDF", :type=>:record
>>>
>>> and i defined
>>>
>>> def generate_pdf
>>> pdf = PDF::Writer.new
>>> pdf.select_font("Helvetica")
>>> pdf.text("Ciao Ale")
>>> #pdf.text("Hello Ruby.HTML.it", 72, :justification=>center)
>>> pdf.save_as("public/example.pdf")
>>> end
>>>
>>> The pdf is correct but there is an error
>>> - ActionController::MissingTemplate (Missing template admin/dmwaters/
>>> generate_pdf.html.erb
>>>
>>> but I would like to bring up the message "PDF Generate ok" like Error
>>> Message in active scaffold.
>>>
>>> Thanks for all
>>>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---