Skip to content

Instantly share code, notes, and snippets.

@radar
Created January 23, 2012 05:23
Show Gist options
  • Select an option

  • Save radar/1660803 to your computer and use it in GitHub Desktop.

Select an option

Save radar/1660803 to your computer and use it in GitHub Desktop.
<% if Spree::Config[:address_requires_state] %>
<% have_states = !@order.ship_address.country.states.empty? %>
<%= ship_form.label :state, t(:state) %><span>*</span>
<noscript>
<%= ship_form.text_field :state_name %>
</noscript>
<% state_elements = [
ship_form.collection_select(:state_id, @order.ship_address.country.states,
:id, :name,
{:include_blank => true},
{:class => have_states ? 'required' : 'hidden',
:disabled => !have_states}) +
ship_form.text_field(:state_name,
:class => !have_states ? 'required' : 'hidden',
:disabled => have_states)
].join.gsub('"', "'").gsub("\n", "")
%>
<%= javascript_tag do -%>
document.write("<%== state_elements %>");
<% end %>
<% end %>
<% if Spree::Config[:address_requires_state] %>
<% have_states = !@order.ship_address.country.states.empty? %>
<%= ship_form.label :state, t(:state) %><span>*</span>
<noscript>
<%= ship_form.text_field :state_name %>
</noscript>
<% state_elements = [ship_form] %>
<%= javascript_tag do %>
document.write("<%== state_elements %>");
<% end %>
<% end %>
def ship_form
ship_form.collection_select(
:state_id,
@order.ship_address.country.states,
:id,
:name,
{:include_blank => true},
{helper1}
) +
ship_form.text_field(helper2)
end
# What should I call this instead of helper1?
#
def helper1
if :class => have_states
"required"
else
"hidden", :disabled => !have_states
end
end
# What should I call this instead of helper2?
#
def helper2
:state_name
if :class => !have_states
"required"
else
"hidden", :disabled => have_states
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment