Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 656809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:45:17+00:00 2026-05-13T22:45:17+00:00

Here is my chunk of code: var update_shipping_methods = function(methods) { $(methods).each( function(i) {

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:45:17+00:00Added an answer on May 13, 2026 at 10:45 pm

    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:

     var update_shipping_methods = function(methods, condition) {
       ...
       var s = condition ? this.name : this.name + ' ' + this.rate;
       ...
     }
    

    Then, when you generate the calls in your view, you can include the rails condition on the parameter, like this:

    <script language='text/javascript'>
      update_shipping_methods(methods, <%= your_rails_condition %>);
    </script>
    

    If adding a parameter is not possible, then the second best solution is adding a global variable called rails_condition on the javascript:

     var rails_condition = false; // default value
     var update_shipping_methods = function(methods) {
       ...
       var s = rails_condition ? this.name : this.name + ' ' + this.rate;
       ...
     }
    

    Then on your view:

    <script language='text/javascript'>
      rails_condition = <%= your_rails_condition %>;
    </script>
    

    Regards!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is a simple chunk of code: 1 var selected_clone = selected.clone(); 2 alert(selected_clone.text());
I'm learning jQuery and saw this chunk of code. myJqueryFile.js (function($, undefined) { function
Here's what this chunk of code does: Pulls back the 6 most recent members
I'm using meteor with the bootstrap package. (here is a chunk of code where
I will be using some jQuery below this chunk of code (which I may
I have this chunk of code which I found and implemented according to http://www.activexperts.com/activmonitor/windowsmanagement/scripts/networking/windowsfirewall/
I'm using nodejs 0.4.7 to make the request, this is my code: var post_data
I have the following chunk of code in my constructor (This is just an
Here's the code I'm using to download a file var S3_KEY = 'xxxxxx'; var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.