Never been to TextSnippets 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 (or not, you can keep them private!)

About this user

Aaron http://www.stocad.com

« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

Adding an error to the model

// description of your code here
How to manually add errors to the model
Should probably be done as part of the validate callback

self.errors.add :field_name, "isn't as it should be"

Radio button with observer field

This is a clip of a radio button that updates a field with ajax on changes.

<%= radio_button_tag "payment_method_token", pm.token, (@payment_method_token == pm.token ? true : false), {:onchange => remote_function(       :with => "'payment_method_token='+this.value", :url => {:action => 'load_payment_method' } )}%>
>
<TD nowrap><B><%=pm.name%>
<%=pm.description%>>
TR>
<%}%>
<% observe_field('payment_method_token', :frequency => 0.5,
                         :with => "payment_method_token",
                         :url => { :action => 'load_payment_method' }) 
%>

Link to Remote Tag

Tag for creating ajax callback links

<%= link_to_remote( "click here",
                         :update => "specific_div_block",
                         :url =>{ :action => :action_name }) %>

Active Selection Box (drop down) examples

// description of your code here

<%= select_tag( :saction, options_for_select([["Actions:",0],["Edit",1],["Delete",2]],0),
                                :onchange => "if(confirm('Are you sure?  This will effect all products checked below.')) products_form.submit(); else products_form.saction.value = 0;")%>


<%= select_tag( :sort_by, options_for_select([["Sort by:",0],["Name",'name'],["Price",'price'], ["Date Listed",'id']],0),
                                :onchange => remote_function(        :with => "'sort_by='+$(\"sort_by\").value",
                                                                                                :loading => "false;",
:url => { :controller => 'products', :action => :change_order } )
)  %>

Link Tag

Basic rails link tag

<%= link_to 'Link Name', { :action => 'action_name', :id => 0 }, :confirm => 'Are you sure?', :post => true %>
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed