Walter Lee D. wrote:
I posted a question yesterday about the Mailer extension, and it occurs
to me that it might have come off too “needy”. I am just starting with
Rails and Ruby, and stumbled across Radiant, which can already do about
80% of what I need “out of the box”. Could someone tell me, in general
terms, if I will need to learn to fully develop in Rails before I can
do things like validate a form submission within Radiant? Does being
able to create an extension equate with being able to create a Rails
app? Or will I be able to skate along without coming all the way up
that learning curve, and learn as I have always done, by picking apart
other people’s solutions and modifying them to my needs?
Learning Rails would definitely help you understand how Radiant works,
but Radiant does a number of things on it’s own that aren’t particularly
Railsish. Creating your own extensions would definitely help you get the
hang of Radiant, but unfortunately documentation is a bit thin right now
so you will probably need to resort to reading the source code more
often than not. Studying the way other extensions are written will also
help.
Sorry not to answer your other question right away. In general if you
want a form in Radiant that displays error messages you need to create a
number of tags for displaying error messages.
Here’s an example from a small plugin I wrote for the Ruby Lang Web site
to simplify subscribing to the Ruby-Mailing lists:
<r:subscribe>
<r:unless_success>
Mailing-lists are a great way to keep your finger on the pulse of
the Ruby community.
<r:form id="subscriptions-form">
<h2>Subscribe or Unsubscribe</h2>
<r:if_error><p class="error"><r:error_message /></p></r:if_error>
<p>
Mailing List: <r:list_select /><br />
First Name: <r:first_name_input /><br />
Last Name: <r:last_name_input /><br />
E-mail Address: <r:email_input /><br />
Action: <r:action_select />
</p>
<div class="buttons">
<input class="button" type="submit" value="Submit Form" />
</div>
</r:form>
</r:unless_success>
<r:if_success>
Confirmation E-mail
You should receive a confirmation message within a few minutes.
Once you have received the message, follow the instructions it
contains to complete the process.
<r:link>Subscribe to another mailing list…</r:link>
</r:if_success>
</r:subscribe>
You can see this in action here:
http://www.ruby-lang.org/en/community/mailing-lists/
In a nutshell the form tag on the Subscribe page submits to the current
URL. The Subscribe page then has a chance to process the request. It
checks for a post and if it’s a post it processes the request. If there
are no errors it sets success to true and the part in the <r:if_success>
tags renders. If it can’t process the form because their are errors it
sets the error message and that will be displayed above the form.
Extremely messy, I know, especially by Rails standards, but this is the
cleanest implementation I could come up with that worked with tags.
I’ve attached the complete Behavior for your perusal that was designed
to work with 0.5.2. It works slightly differently on mental and the 0.6
release candidates because behaviors have been merged with the Page
class, but this is the general idea.