<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: action code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 03:44:00 GMT</pubDate>
    <description>DZone Snippets: action code</description>
    <item>
      <title>A simple XHTML submit form for ProjectX</title>
      <link>http://snippets.dzone.com/posts/show/5354</link>
      <description>Preparing ProjectX API requests through the browser's address bar  can get quite messy, however inputting the request through a simple form makes it much easier to read.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"&lt;br /&gt;  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;&lt;br /&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;&lt;br /&gt;  &lt;head&gt;&lt;br /&gt;    &lt;title&gt;ProjectX API&lt;/title&gt;&lt;br /&gt;    &lt;meta http-equiv="Content-Type" content="text/html;charset=utf-8"/&gt;&lt;br /&gt;  &lt;/head&gt;&lt;br /&gt;  &lt;body&gt;&lt;br /&gt;    &lt;h1&gt;ProjectX API form&lt;/h1&gt;&lt;br /&gt;    &lt;p&gt;Enter the Project API XML to send a request to the server.&lt;/p&gt;&lt;br /&gt;    &lt;form action="http://rorbuilder.info/api/projectx.cgi" method="post" id="projectx_form"&gt;&lt;br /&gt;    &lt;fieldset&gt;&lt;legend&gt;xml_project&lt;/legend&gt;&lt;textarea id="xml_project" name="xml_project" cols="104" rows="20"&gt;&lt;/textarea&gt;&lt;/fieldset&gt;&lt;br /&gt;    &lt;div&gt;&lt;button type="submit"&gt;Submit&lt;/button&gt;&lt;/div&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;  &lt;p&gt;&lt;br /&gt;    &lt;a href="http://validator.w3.org/check?uri=referer"&gt;&lt;img&lt;br /&gt;        src="http://www.w3.org/Icons/valid-xhtml10"&lt;br /&gt;        alt="Valid XHTML 1.0 Strict" height="31" width="88" style="float:right;  border:0 "/&gt;&lt;/a&gt;&lt;br /&gt;  &lt;/p&gt;&lt;br /&gt;  &lt;p style="clear:float"&gt;last updated: 13th April 2008&lt;/p&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;/body&gt;&lt;br /&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The web page can be seen at http://rorbuilder.info/r/projectx-api/index.html&lt;br /&gt;The following XML request value when submitted should return an XML result containing the results and the method executed.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;project name='whiteboardqueue'&gt;&lt;br /&gt;  &lt;methods&gt;&lt;br /&gt;    &lt;method name='get_user_id'&gt;&lt;br /&gt;      &lt;params/&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/methods&gt;&lt;br /&gt;&lt;/project&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;eg.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;result method="rtn_get_user_id"&gt;&lt;br /&gt;  &lt;get_user_id&gt;36539&lt;/get_user_id&gt;&lt;br /&gt;&lt;/result&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 13 Apr 2008 22:32:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5354</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Ajax style radio buttons</title>
      <link>http://snippets.dzone.com/posts/show/3799</link>
      <description>Ajax radio buttons. update the page div when a radio button is pressed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div id="join"&gt;&lt;br /&gt;        &lt;p class="title"&gt;&lt;br /&gt;      Sign-up&lt;br /&gt;        &lt;/p&gt;&lt;br /&gt;   &lt;% form_for :radio_join, :html =&gt; { :id =&gt; 'radio_join' } do %&gt;&lt;br /&gt;      &lt;%= radio_button_tag :join_page, :member %&gt; Member&lt;br /&gt;      &lt;%= radio_button_tag :join_page, :model %&gt; Model&lt;br /&gt;      &lt;%= radio_button_tag :join_page, :photographer %&gt; Photographer&lt;br /&gt;    &lt;% end -%&gt;&lt;br /&gt;&lt;% form_for :user, @user, :url =&gt; {:action =&gt; 'save_free'} do |user_form| -%&gt;&lt;br /&gt;        &lt;div class="info"&gt;&lt;br /&gt;    &lt;%= render :partial =&gt; 'common/user_form', :object =&gt; user_form %&gt;&lt;br /&gt;                &lt;p class="alignright"&gt;&lt;br /&gt;        &lt;%= submit_tag 'JOIN', :class =&gt; 'inputSubmit' %&gt;&lt;br /&gt;                &lt;/p&gt;&lt;br /&gt;      &lt;br /&gt;&lt;br /&gt;      &lt;br /&gt;&lt;br /&gt;        &lt;/div&gt;&lt;br /&gt;  &lt;% end -%&gt;&lt;br /&gt;&lt;br /&gt;     &lt;/div&gt;&lt;br /&gt;&lt;%= observe_form :radio_join, :url =&gt; { :action =&gt; 'choose_page' }, :update =&gt; "join", :complete =&gt; "Element.show('join')", :frequency =&gt; "0.25" %&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 11 Apr 2007 21:16:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3799</guid>
      <author>mcarr (matt)</author>
    </item>
    <item>
      <title>Redirect back to a previous action</title>
      <link>http://snippets.dzone.com/posts/show/1052</link>
      <description>I am pasting this verbatim from LoginSystem&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# move to the last store_location call or to the passed default one&lt;br /&gt;  def redirect_back_or_default(default)&lt;br /&gt;    if @session[:return_to].nil?&lt;br /&gt;      redirect_to default&lt;br /&gt;    else&lt;br /&gt;      redirect_to_url @session[:return_to]&lt;br /&gt;      @session[:return_to] = nil&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In your controller...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; redirect_back_or_default :controller =&gt; "myfuel", :action =&gt; "index"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 04 Jan 2006 18:08:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1052</guid>
      <author>pmark (P. Mark Anderson)</author>
    </item>
    <item>
      <title>Firing a controller's action from the console</title>
      <link>http://snippets.dzone.com/posts/show/600</link>
      <description>It seems like a simple task, but here's how you can simulate the calling of a controller's action:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby script/console&lt;br /&gt;&lt;br /&gt;irb&gt; require 'action_controller/test_process'&lt;br /&gt;irb&gt; require 'application'&lt;br /&gt;irb&gt; require 'site_controller'&lt;br /&gt;irb&gt; request = ActionController::TestRequest.new&lt;br /&gt;irb&gt; response = ActionController::TestResponse.new&lt;br /&gt;irb&gt; request.env['REQUEST_METHOD'] = 'GET'&lt;br /&gt;irb&gt; request.action = "late_employee"&lt;br /&gt;irb&gt; InfoController.process(request,response)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Basically, it's like getting inside of a TestUnit method, but you have to do the dirty work yourself.</description>
      <pubDate>Fri, 26 Aug 2005 02:44:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/600</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
