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 7578719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:29:51+00:00 2026-05-30T17:29:51+00:00

Hi I’ve the following code: def update_for_transport_document # => DESCRIPTION: # => Utilizzata nelle

  • 0

Hi I’ve the following code:

def update_for_transport_document
    # => DESCRIPTION:
    # => Utilizzata nelle form di associazione di un warehouse ad una bolla
    @wh_errors = Hash.new

    if request.path.include? "ingress_transport_document"
        session[:user_role] != "administrator" ?
            @itd = IngressTransportDocument.filtered_by_registry(session[:registry_id]).find(params[:warehouse][:ingress_transport_document_id]) :
            @itd = IngressTransportDocument.find(params[:warehouse][:ingress_transport_document_id])
            @all_itd = IngressTransportDocument.all
            logger.debug { "INGRESS_TRANSPORT_DOCUMENT_ID: #{@itd.id} " }
           @warehouse = Warehouse.find(params[:warehouse][:id])

           #check_warehouse_in_td(@all_itd,@warehouse)
          @all_itd.each do |td|
            td.warehouses.each do |whs|
                logger.debug {"TD WAREHOUSES:#{whs.id} && #{@warehouse.id}"}
                    if whs.id == @warehouse.id
                     @ok = 'ciccia'
                     break
                   break
              end               
       end
       end
       logger.debug {"OK:#{@ok} "}
        if @ok != 'ciccia'  
  @itd.warehouses << @warehouse

           else
            logger.debug{"NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"}
           end  
              respond_to do |format|   
         format.html { redirect_to(@itd) }
            format.xml  { head :ok }
            end



    else 

        session[:user_role] != "administrator" ?
            @etd = EgressTransportDocument.filtered_by_registry(session[:registry_id]).find(params[:warehouse][:ingress_transport_document_id]) :
            @etd = EgressTransportDocument.find(params[:warehouse][:ingress_transport_document_id])
            logger.debug { "TEST" }
            logger.debug { "EGRESS_TRANSPORT_DOCUMENT_ID: #{@etd.id}" }
               @warehouse = Warehouse.find(params[:warehouse][:id])
           logger.debug { "WAREHOUSE_ID: #{@warehouse.id}" }
    @etd.warehouses << @warehouse
             respond_to do |format|
               format.html { redirect_to(@etd) }
               format.xml  { head :ok } 
          end
      end

end

and I’d want that @warehouse can be append to @itd(@etd).warehouses only if the same warehouse is not present in others ingress(egress)transport documents.

My issue is that using this code any warehouse can be append to @itd(@etd).warehouses both if warehouse is present in another transport document neither if it’s a new one not associated to any itd/etd.

Where’s the mistake?

  • 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-30T17:29:52+00:00Added an answer on May 30, 2026 at 5:29 pm

    It’s really hard to find bug in your code.

    I will not try to guess which single line makes errors, instead I will give you few hints:

    There is general rule in Rails environment fat models - skinny controllers. For your code it means: leave only the minimum over code generated by scaffolding. All business logic move into models. You may ask why: there are few reasons: you can reuse your code, it’s much easier to make unit test against model than controller.

    I would really encourage you to try build unit test for logic in your model. It is much efficient than debugging. However debugger is still powerfull tool, I use debugger from Rubymine. Debugger gives you possibility to inspect all variables state in line-by-line application execution.

    One thing in your code: overuse of ? operator

    session[:user_role] != "administrator" ?
            @itd = IngressTransportDocument.filtered_by_registry(session[:registry_id]).find(params[:warehouse][:ingress_transport_document_id]) :
            @itd = IngressTransportDocument.find(params[:warehouse][:ingress_transport_document_id])
    

    Is less readable than:

    if session[:user_role] != "administrator" then
        @itd = IngressTransportDocument.filtered_by_registry(session[:registry_id]).find(params[:warehouse][:ingress_transport_document_id]) 
    else
        @itd = IngressTransportDocument.find(params[:warehouse][:ingress_transport_document_id])
    end if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and

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.