Re: [Radiant] Forms extension

2010-11-12 Thread Wes Gamble
I used apotonick's cells so that I could embed a regular Rails form 
(rendered through Rails) in a Radiant page.  I found the Radiant 
extension too limiting.


This is rather involved though.  What I like about it is I can embed 
arbitrarily complex forms without having to leave the Radiant rendering 
system.  I plan to write this up at some point and put it in the Wiki.


At a very high - level, here's how I did that.

1) Install cells 3.3.4 (anything higher is Rails 3 specific)
2) Added these commands so that cells can be processed from within 
Radiant (I did these in a custom extension (and the pathing reflects 
that), but you could theoretically do them anywhere in the 
initialization process, as long as you got the paths right):


CELL_PATH = "#{File.expand_path(File.dirname(__FILE__))}/app/cells"
CELL_FILES = Dir.glob("#{CELL_PATH}/*_cell.rb").map {|f| 
File.basename(f)}


##Cell configuration
#Modify view paths for ::Cell::Base to include local cell view 
directories

::Cell::Base.view_paths += [CELL_PATH, "#{CELL_PATH}/layouts"]

#Add CELL_PATH to Rails $LOAD_PATH
$LOAD_PATH.unshift CELL_PATH

#Require each Cell class
CELL_FILES.each {|f| require f}

3) Created cells to render my form.  Here's an example:

  app/cells/question_instances_cell.rb:

class QuestionInstancesCell < ::Cell::Base
  def new
@question_type = QuestionType.find(@opts['question_type_id'])
if @question_type.question_type =~ /FAQ/
  @question_instance = QuestionInstance.new()
  view = :edit_faq
else
  @question_instance = QuestionInstance.new(:question => 
@question_type.questions.first)

  view = :edit
end

render :view => view
  end
end

/app/cells/question_instances:

-rw-r--r--@ 1 weyus  staff  568 Aug 30 16:46 edit.html.haml
-rw-r--r--@ 1 weyus  staff  658 Sep  6 13:21 edit_faq.html.haml

/app/cells/question_instances/edit.html.haml:

- type = @question_type.question_type
- form_for [:admin, @question_instance] do |f|
  = f.error_messages
  %p
= type
%br/
= f.select :question_id, @question_type.questions.map {|q| 
[q.question, q.id]}

  %p
= f.label :question_text, "Edit the question to best fit your 
selling situation"

%br/
= f.text_area :question_text, :value => 
@question_type.questions.first.question, :class => 'short'

  %p
= f.label :new_form, "Would you like to build another #{type} 
question?"

= check_box_tag :new_form, 1, false
  %p
= submit_tag 'Submit'

4) Created a custom tag to allow for a cell to be rendered inside of a 
Radiant template:


tag "cell" do |tag|
  if tag.attr['name'] && tag.attr['view']
name, view = tag.attr.delete('name'), tag.attr.delete('view')
tag.locals.page.response.template.controller.render_cell(name, 
view, tag.attr)

  else
raise TagError.new("`cell' tag must contain `name' and `view' 
attributes")

  end
end

5) Call the tag from my Radiant template:



Wes


On 11/12/10 9:34 AM, Marshal Linfoot wrote:
Has anyone used a forms/mailer extension for Radiant that allows a 
file to be attached and sent with the form? I have a form working -- 
users fills in text, selects choices from dropdown, checks radio 
buttons -- everything works, contents emailed successfully. I'm trying 
to add the capability for people to select a file (photo) from their 
computer to be attached to the email but I can't get it to work. If 
you've got it working, could you please share your solution?


Many thanks.
--
marshal


Re: [Radiant] Forms extension

2010-11-12 Thread john muhl
On Fri, Nov 12, 2010 at 9:34 AM, Marshal Linfoot  wrote:
> Has anyone used a forms/mailer extension for Radiant that allows a file to
> be attached and sent with the form? I have a form working -- users fills in
> text, selects choices from dropdown, checks radio buttons -- everything
> works, contents emailed successfully. I'm trying to add the capability for
> people to select a file (photo) from their computer to be attached to the
> email but I can't get it to work. If you've got it working, could you please
> share your solution?

try the aissac fork. i've setup mailer with attachments before and i
think that was the fork i used (if not poke around the network and
you'll find it).


[Radiant] Forms extension

2010-11-12 Thread Marshal Linfoot
Has anyone used a forms/mailer extension for Radiant that allows a file to
be attached and sent with the form? I have a form working -- users fills in
text, selects choices from dropdown, checks radio buttons -- everything
works, contents emailed successfully. I'm trying to add the capability for
people to select a file (photo) from their computer to be attached to the
email but I can't get it to work. If you've got it working, could you please
share your solution?

Many thanks.
-- 
marshal


Re: [Radiant] Forms Extension

2010-11-07 Thread Marshal Linfoot
Thanks Jim. Here's the pastie: http://pastie.org/1279841

Is the "Yajl::ParseError" caused by the FormsController trying to parse the
file that was uploaded? If so, what to do about it?

 I'm totally lost here, so any suggestions for troubleshooting would be much
appreciated.
-- 
marshal


Re: [Radiant] Forms Extension

2010-11-07 Thread Jim Gay
On Nov 7, 2010, at 8:12 AM, Marshal Linfoot wrote:

> Greetings.
> 
> I'm using the forms and forms-mailer extensions to create a form to be 
> emailed. Most of it is working well except for attachments. I've used the 
>  tag to get a file chooser button/dialog and that appears to work. In 
> the "content" page of the form, what gets emailed, I've used  to get 
> the uploaded file, but when the form is submitted, a 500 application error is 
> given "for exceptions thrown outside of an action".
> 
> What am I missing? Thanks for any suggestions.
> 
> -- 
> marshal

I don't really know those extensions at all, but you'll need to look at your 
log file.

From the root directory of your app, run "tail -500 log/production.log"
That will  show you the last 500 lines of your production log. Look there for 
details about the actual error. If you need more help, copy what you find into 
a pastie and reply back.

-Jim

Jim Gay
Saturn Flyer LLC
www.saturnflyer.com
571 - 403 - 0338







[Radiant] Forms Extension

2010-11-07 Thread Marshal Linfoot
Greetings.

I'm using the forms and forms-mailer extensions to create a form to be
emailed. Most of it is working well except for attachments. I've used the
 tag to get a file chooser button/dialog and that appears to work.
In the "content" page of the form, what gets emailed, I've used  to
get the uploaded file, but when the form is submitted, a 500 application
error is given "for exceptions thrown outside of an action".

What am I missing? Thanks for any suggestions.

-- 
marshal


[Radiant] Forms extension and RESTful ruoting mechanics

2010-08-16 Thread Wes Gamble
 Is there anything about squaretalent's forms extension 
(http://github.com/squaretalent/radiant-forms-extension) that conflicts 
with standard RESTful routing semantics for form targets?


Thanks,
Wes