Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

A simple XHTML submit form for ProjectX

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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>ProjectX API</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  </head>
  <body>
    <h1>ProjectX API form</h1>
    <p>Enter the Project API XML to send a request to the server.</p>
    <form action="http://rorbuilder.info/api/projectx.cgi" method="post" id="projectx_form">
    <fieldset><legend>xml_project</legend><textarea id="xml_project" name="xml_project" cols="104" rows="20"></textarea></fieldset>
    <div><button type="submit">Submit</button></div>
    </form>
  <p>
    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Strict" height="31" width="88" style="float:right;  border:0 "/></a>
  </p>
  <p style="clear:float">last updated: 13th April 2008</p>
  
  </body>
</html>


The web page can be seen at http://rorbuilder.info/r/projectx-api/index.html
The following XML request value when submitted should return an XML result containing the results and the method executed.
<project name='whiteboardqueue'>
  <methods>
    <method name='get_user_id'>
      <params/>
    </method>
  </methods>
</project>

eg.
<result method="rtn_get_user_id">
  <get_user_id>36539</get_user_id>
</result>

Ajax style radio buttons

Ajax radio buttons. update the page div when a radio button is pressed.

<div id="join">
        <p class="title">
      Sign-up
        </p>
   <% form_for :radio_join, :html => { :id => 'radio_join' } do %>
      <%= radio_button_tag :join_page, :member %> Member
      <%= radio_button_tag :join_page, :model %> Model
      <%= radio_button_tag :join_page, :photographer %> Photographer
    <% end -%>
<% form_for :user, @user, :url => {:action => 'save_free'} do |user_form| -%>
        <div class="info">
    <%= render :partial => 'common/user_form', :object => user_form %>
                <p class="alignright">
        <%= submit_tag 'JOIN', :class => 'inputSubmit' %>
                </p>
      <br />
      <br />
        </div>
  <% end -%>

     </div>
<%= observe_form :radio_join, :url => { :action => 'choose_page' }, :update => "join", :complete => "Element.show('join')", :frequency => "0.25" %>

Redirect back to a previous action

I am pasting this verbatim from LoginSystem

# move to the last store_location call or to the passed default one
  def redirect_back_or_default(default)
    if @session[:return_to].nil?
      redirect_to default
    else
      redirect_to_url @session[:return_to]
      @session[:return_to] = nil
    end
  end


In your controller...

 redirect_back_or_default :controller => "myfuel", :action => "index"

Firing a controller's action from the console

It seems like a simple task, but here's how you can simulate the calling of a controller's action:

ruby script/console

irb> require 'action_controller/test_process'
irb> require 'application'
irb> require 'site_controller'
irb> request = ActionController::TestRequest.new
irb> response = ActionController::TestResponse.new
irb> request.env['REQUEST_METHOD'] = 'GET'
irb> request.action = "late_employee"
irb> InfoController.process(request,response)


Basically, it's like getting inside of a TestUnit method, but you have to do the dirty work yourself.
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS