Re: checkbox value always returns true value when puts to console

Actually they are

Where is the code that sets the attributes then?

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: checkbox value always returns true value when puts to console

you have shown me no code that assigns those attributes. Just how do you expect the application object to have values on it that you do not set.
all you have done is shown me some code that assigns a hard coded value of "email@gmail.com" to the guardian_email attribute then checks if that the assignment worked

if @application.guardian_email = "email@gmail.com"
  # do this
else
# do that
end

Is not checking that the value held @application.guardian attribute is equal to "emai@guardian.com" it is checking that the assignment of the string "email@gmail.com" to @application.guardian worked.

If you want to compare string values the use == or eq?()

if @application.guardian_email.to_s == "email@gmail.com"
#Or @application.guardian_email.eql?( "email@gmail.com")
  # do this
else
# do that
end

My previous answer stands and it is the solution to your problem

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: checkbox value always returns true value when puts to console

jamesw wrote:

Actually they are

Where is the code that sets the attributes then?


    def update
      @application.validate_partner_details = true
      @application.update_attributes(application_params)
    end

    def application_params
      params.require( :application ).permit(
        :full_name, :telephone, :address_1, :address_2,
        :adult, :guardian_full_name, :guardian_email
      )
    end

Re: checkbox value always returns true value when puts to console

If you want to compare string values the use == or eq?()

if @application.guardian_email.to_s == "email@gmail.com"
#Or @application.guardian_email.eql?( "email@gmail.com")
  # do this
else
# do that
end

I know how to compare things, if you'd looked at my early code, before it was almost 5am where I am, you'd see that over and over again I've written that correctly. You're still not disproving why @application.guardian_email works in the conditional statement with your belief that I not updating the attributes.

Re: checkbox value always returns true value when puts to console

You showed me the following output

Started PUT "/user/partner_acceptances/55" for ip at 2013-03-19 03:20:50 -0700
Processing by Users::SomeController#update as JSON
Parameters: {"utf8"=>"✓", "authenticity_token"=>"removed", "application"=>{"full_name"=>"Full Name", "address_1"=>"123 Sesame Street", "adult"=>"1", "guardian_full_name"=>"G Name", "telephone"=>"3141592653", "address_2"=>"Beverly Hills, CA 90210", "guardian_email"=>"email@gmail.com"}, "id"=>"55"}

then there's a bunch of sql stuff which I cannot imagine you'd need, then

Started GET "/user/partner_acceptances55/partner_agreements/new" for ip at 2013-03-19 03:20:51 -0700
Processing by Users::SomeController
Parameters: {"partner_id"=>"55"}

which is a "new" action

#new as HTML

and has absolutely NOTHING to do with the update action you just posted.

I assume that that action looks like this

module Users
  class SomeController < ApplicationController
    include BaseConcern
    include PartnerApplicationConcern
    before_filter :set_application
   
    def new
     
      if @application.adult?

        response = request_agreement
       
        unless response.nil?
          @application.update_attribute( :agreement_key, response.document_key )
           redirect_to response.url
        end
      else

        response = request_minor_agreement
       
        unless response.nil?
          @application.update_attribute( :agreement_key, response.document_key )
        end

      end

    end
  end
end

If I have that wrong then please state the full sequence of events

As for

You're still not disproving why @application.guardian_email works in the conditional statement with your belief that I not updating the attributes.

I don't really understand what you are asking here
if @application.guardian_email = "email@gmail.com" will always return true regardless of the value of @application.guardian_email
e.g.

@application.guardian_email = "fred"
if @application.guardian_email = "email@gmail.com"
#  this condition will always be met. and the value of @application.guardian_email will now be email@gmail.com
end

You used that statement to prove that attributes are being set when it proves absolutely nothing

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: checkbox value always returns true value when puts to console

You need to try to get to the bottom of why the adult attribute is not being set to the value you have in the form.
A recap
You have shown me a form that now correctly sets the value of the adult attribute in the params hash sent back to the server (to what action?) using a checkbox
1) You proved to me that the correct values are coming through in the params hash in the controller action.
2) You showed me some sql that was setting the adult value.
3) You showed me an action that checks the value of the adult attribute on the @application object
4) You have shown me an update action that does no checks whatsoever as to whether the save worked or not and I have no idea where that update action fits into the life cycle of what you are trying to achieve.
5) I questioned that the attributes were not being set. You showed me soe code that does not prove that they are being set but if thety are actually being set then the value is not being saved to the database

work with me on this as I am trying to help but you are not making it easy for me to do so

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: checkbox value always returns true value when puts to console

Before you check the condition of the adult attribute put some debug code in and show me the output

    def new
      logger.debug("@@@@ Application state is #{@application.inspect}")
      if @application.adult?
What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: checkbox value always returns true value when puts to console

?

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)