prawn with authentication?

13 views
Skip to first unread message

Tyron Power

unread,
Nov 4, 2009, 8:40:02 AM11/4/09
to Prawn
Hello,
I'm trying to figure that by myself, but no success so far...

I'd like...
- not to use prawnto
- to use authlogic+lockdown/acl9 (may be devise soon)
- to generate private PDFs for specific authenticated users
- to let each user have access only to her own documents

Maybe you have some king suggestions? An outline would be more than
enough :-)

Thank you very much in advance,
Regards,

Tyron

Gregory Brown

unread,
Nov 4, 2009, 10:55:07 AM11/4/09
to prawn...@googlegroups.com
On Wed, Nov 4, 2009 at 8:40 AM, Tyron Power <tyrona...@gmail.com> wrote:
>
> Hello,
> I'm trying to figure that by myself, but no success so far...
>
> I'd like...
> - not to use prawnto

Then this is the same as using any other Ruby library. If you're
using config.gem you may need to futz around with it so rails loads
the right stuff, but otherwise, nothing special here. Shelve your
reports somewhere in the loadpath and fire away.

> - to use authlogic+lockdown/acl9 (may be devise soon)

Doesn't sound related to Prawn.

> - to generate private PDFs for specific authenticated users

Not sure whether you're talking about security at the PDF level or the
application level. If you either stream the PDFs on demand, or create
hashed download URLs and check your user credentials there, that
should do the trick on the application level. If you're looking at
building passworded or encrypted PDFs, have a look at prawn-security.

http://github.com/madriska/prawn-security

This is technically unsupported in Prawn <=0.5.x, but is inbound for
becoming part of the Prawn 0.6 release, so it's ready for use.

> - to let each user have access only to her own documents

Isn't this accomplished by your previous questions?

Tyron Power

unread,
Nov 5, 2009, 3:33:07 AM11/5/09
to Prawn
Hem... :-) maybe I will need more than an outline...
Actually, I started rails in my spare time some weeks ago, and I never
integrated a library in rails.
You are right, I meant application security level.
I found that the method render instead of render_file should be better
for my purpose.
Moreover in the docs it says not to put PDF code in the controller...
I will try in practice... maybe you think I should use prawnto, but I
would like to depend on the least components as possible...
Thanks for your tips... I will let you know....
Tyron


On Nov 4, 4:55 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:

Gregory Brown

unread,
Nov 5, 2009, 9:07:59 AM11/5/09
to prawn...@googlegroups.com
On Thu, Nov 5, 2009 at 3:33 AM, Tyron Power <tyrona...@gmail.com> wrote:
>
> Hem... :-) maybe I will need more than an outline...
> Actually, I started rails in my spare time some weeks ago, and I never
> integrated a library in rails.

That's something you'll need to get over on the Rails mailing list,
though. There isn't anything special about using Prawn in Rails, so
all of the questions are basically about Rails and would be better
served by that community.

> I found that the method render instead of render_file should be better
> for my purpose.

Sure, or you can use send_data if you don't want to bother writing to
file. Depends on your needs.

> Moreover in the docs it says not to put PDF code in the controller...

Typically this just means that you do something like this:

MyFancyReport.render_pdf

> I will try in practice... maybe you think I should use prawnto, but I
> would like to depend on the least components as possible...

Not to discourage those who find Prawnto useful, but I have never used
it and probably would never have a need for it. Any Prawn work I've
done in Rails has been just directly with Prawn.

-greg

Tyron Power

unread,
Nov 6, 2009, 4:30:53 AM11/6/09
to Prawn
Thank you Greg for your reply,
I'm sorry to bother you, I've been trying during these days but I'm
still in trouble. Too bad my skills-level are limited to use rails
built-in mechanisms, I'm still not able to extend Rails, even if this
particular case could be a trivial task.
Maybe you could point me to some sample Rails project directly using
prawn? This could help me a lot.
Thank you very much,
Tyron



On Nov 5, 3:07 pm, Gregory Brown <gregory.t.br...@gmail.com> wrote:

Henrik Nyh

unread,
Nov 6, 2009, 9:35:42 AM11/6/09
to prawn...@googlegroups.com
On Fri, Nov 6, 2009 at 10:30, Tyron Power <tyrona...@gmail.com> wrote:
>
> Thank you Greg for your reply,
> I'm sorry to bother you, I've been trying during these days but I'm
> still in trouble. Too bad my skills-level are limited to use rails
> built-in mechanisms, I'm still not able to extend Rails, even if this
> particular case could be a trivial task.
> Maybe you could point me to some sample Rails project directly using
> prawn? This could help me a lot.

Without Prawnto, you could do something like

class MyController < ApplicationController

def my_action
pdf = Prawn::Document.new(:page_size => "A4") do
text "Hello world."
end

send_data(pdf.render, :type => 'application/pdf', :disposition
=> 'attachment',
:filename => 'hello_world.pdf')
end

end

Then you could tidy this up by making your own class that inherits
from Prawn::Document or that wraps around it, so you might have

pdf = HelloWorldDocument.new

instead. And you could of course define your own send_pdf controller
method to tidy up the send_data bit.

Gregory Brown

unread,
Nov 6, 2009, 10:02:12 AM11/6/09
to prawn...@googlegroups.com
On Fri, Nov 6, 2009 at 4:30 AM, Tyron Power <tyrona...@gmail.com> wrote:
>
> Thank you Greg for your reply,
> I'm sorry to bother you, I've been trying during these days but I'm
> still in trouble. Too bad my skills-level are limited to use rails
> built-in mechanisms, I'm still not able to extend Rails, even if this
> particular case could be a trivial task.
> Maybe you could point me to some sample Rails project directly using
> prawn? This could help me a lot.

I'm sorry Tyron, but Prawn is an alpha-level, hackers-only framework
at the moment. Unless you're comfortable reading its source and
fixing things yourself, you really should wait until 1.0. If you
need help configuring a Rails app, ask the Rails list.

-greg

Tyron Power

unread,
Nov 7, 2009, 9:33:05 AM11/7/09
to Prawn
Thank you very much Henrik!
It works fine, it is as simple as effective!
Actually your suggestion made me explore new things in Rails, and
that's even better!
Also thanks to Gregory: I like prawn very much, it works damn well to
be in alpha-stage! :-)
Tyron

On Nov 6, 3:35 pm, Henrik Nyh <hen...@nyh.se> wrote:

Gregory Brown

unread,
Nov 7, 2009, 10:46:14 AM11/7/09
to prawn...@googlegroups.com
On Sat, Nov 7, 2009 at 9:33 AM, Tyron Power <tyrona...@gmail.com> wrote:
>
> Thank you very much Henrik!
> It works fine, it is as simple as effective!
> Actually your suggestion made me explore new things in Rails, and
> that's even better!
> Also thanks to Gregory: I like prawn very much, it works damn well to
> be in alpha-stage! :-)

It's mainly a matter of support. We're not in a position to guarantee
that docs will be up to date, tutorials readily available, etc.
So answering the same beginner questions can be a drain on our
resources. Of course, this is something we can fix with a FAQ, and
luckily other Prawn contributors aren't as curmudgeonly as I am.

I mean it though, by 1.0 Prawn should be relatively easy to use with
lots of resources, even for beginners.

-greg

Reply all
Reply to author
Forward
0 new messages