Here is my chunk of code:
var update_shipping_methods = function(methods) {
$(methods).each( function(i) {
$('div$methods img#shipping_loader').remove();
var p = document.createElement('p');
var s = this.name + ' ' + this.rate;
var i = $(document.createElement('input'))
.attr('id', this.id)
.attr('type', 'radio')
.attr('name', 'checkout[shipment_attributes][shipping_method_id]')
.val(this.id)
.click(function() { $('div#methods input').attr('checked', '');
$(this).attr('checked', 'checked'); });
if($(methods).length == 1) {
i.attr('checked', 'checked');
}
var l = $(document.createElement('label'))
.attr('for', this.id)
.html(s);
$('div#methods').append($(p).append(i).append(l));
});
$('div#methods input:first').attr('validate', 'required:true');
return;
};
the line: var s = this.name + ‘ ‘ + this.rate;
is where I need the if statement. Basically “this” is a shipping name and rate. I need to write an if statement that basically removes the this.rate if “some rails code”
So if “some rails code”;
var s = this.name;
else
var s = this.name + ‘ ‘ + this.rate;
end
Does that make sense? Any thoughts?
If this js code is on a .js file, then I think the best thing is adding an additional parameter to the
update_shipping_methods:Then, when you generate the calls in your view, you can include the rails condition on the parameter, like this:
If adding a parameter is not possible, then the second best solution is adding a global variable called
rails_conditionon the javascript:Then on your view:
Regards!