Change boolean value with hidden_field











up vote
-1
down vote

favorite












I added a MEMBER column to USER.



I am trying to change the value of MEMBER to false via a hidden_field when submit a form.



But the value of the hidden_field does not work!
Why ?



db



class AddMemberToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :member, :boolean, default: true
end
end


users/views/form



<%= form_for(resource, as: resource_name,:html => { :id => "new_user_1"}, url: registration_path(resource_name)) do |f| %>
...
<%= f.hidden_field :member, value: false %>
<%= f.submit "S'inscrire" %>
<% end %>


users/registrations_controllers



class Users::RegistrationsController < Devise::RegistrationsController  
private
def sign_up_params
params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
end

def account_update_params
params.require(:user).permit(:name, :fullname,:avatar,:job, :email, :password, :password_confirmation, :current_password)
end
end


Thanks for your help










share|improve this question






















  • Please you English punctuation when writing in English.
    – sawa
    Nov 8 at 11:06






  • 1




    instead of passing values as true/false. Try passing it as 0/1
    – Gagan Gupta
    Nov 8 at 11:25










  • Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
    – Clyde T
    Nov 8 at 11:39










  • ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
    – Gagan Gupta
    Nov 8 at 11:41










  • @GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
    – Clyde T
    Nov 8 at 11:43















up vote
-1
down vote

favorite












I added a MEMBER column to USER.



I am trying to change the value of MEMBER to false via a hidden_field when submit a form.



But the value of the hidden_field does not work!
Why ?



db



class AddMemberToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :member, :boolean, default: true
end
end


users/views/form



<%= form_for(resource, as: resource_name,:html => { :id => "new_user_1"}, url: registration_path(resource_name)) do |f| %>
...
<%= f.hidden_field :member, value: false %>
<%= f.submit "S'inscrire" %>
<% end %>


users/registrations_controllers



class Users::RegistrationsController < Devise::RegistrationsController  
private
def sign_up_params
params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
end

def account_update_params
params.require(:user).permit(:name, :fullname,:avatar,:job, :email, :password, :password_confirmation, :current_password)
end
end


Thanks for your help










share|improve this question






















  • Please you English punctuation when writing in English.
    – sawa
    Nov 8 at 11:06






  • 1




    instead of passing values as true/false. Try passing it as 0/1
    – Gagan Gupta
    Nov 8 at 11:25










  • Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
    – Clyde T
    Nov 8 at 11:39










  • ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
    – Gagan Gupta
    Nov 8 at 11:41










  • @GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
    – Clyde T
    Nov 8 at 11:43













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I added a MEMBER column to USER.



I am trying to change the value of MEMBER to false via a hidden_field when submit a form.



But the value of the hidden_field does not work!
Why ?



db



class AddMemberToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :member, :boolean, default: true
end
end


users/views/form



<%= form_for(resource, as: resource_name,:html => { :id => "new_user_1"}, url: registration_path(resource_name)) do |f| %>
...
<%= f.hidden_field :member, value: false %>
<%= f.submit "S'inscrire" %>
<% end %>


users/registrations_controllers



class Users::RegistrationsController < Devise::RegistrationsController  
private
def sign_up_params
params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
end

def account_update_params
params.require(:user).permit(:name, :fullname,:avatar,:job, :email, :password, :password_confirmation, :current_password)
end
end


Thanks for your help










share|improve this question













I added a MEMBER column to USER.



I am trying to change the value of MEMBER to false via a hidden_field when submit a form.



But the value of the hidden_field does not work!
Why ?



db



class AddMemberToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :member, :boolean, default: true
end
end


users/views/form



<%= form_for(resource, as: resource_name,:html => { :id => "new_user_1"}, url: registration_path(resource_name)) do |f| %>
...
<%= f.hidden_field :member, value: false %>
<%= f.submit "S'inscrire" %>
<% end %>


users/registrations_controllers



class Users::RegistrationsController < Devise::RegistrationsController  
private
def sign_up_params
params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
end

def account_update_params
params.require(:user).permit(:name, :fullname,:avatar,:job, :email, :password, :password_confirmation, :current_password)
end
end


Thanks for your help







ruby-on-rails






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 10:59









Clyde T

719




719












  • Please you English punctuation when writing in English.
    – sawa
    Nov 8 at 11:06






  • 1




    instead of passing values as true/false. Try passing it as 0/1
    – Gagan Gupta
    Nov 8 at 11:25










  • Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
    – Clyde T
    Nov 8 at 11:39










  • ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
    – Gagan Gupta
    Nov 8 at 11:41










  • @GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
    – Clyde T
    Nov 8 at 11:43


















  • Please you English punctuation when writing in English.
    – sawa
    Nov 8 at 11:06






  • 1




    instead of passing values as true/false. Try passing it as 0/1
    – Gagan Gupta
    Nov 8 at 11:25










  • Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
    – Clyde T
    Nov 8 at 11:39










  • ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
    – Gagan Gupta
    Nov 8 at 11:41










  • @GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
    – Clyde T
    Nov 8 at 11:43
















Please you English punctuation when writing in English.
– sawa
Nov 8 at 11:06




Please you English punctuation when writing in English.
– sawa
Nov 8 at 11:06




1




1




instead of passing values as true/false. Try passing it as 0/1
– Gagan Gupta
Nov 8 at 11:25




instead of passing values as true/false. Try passing it as 0/1
– Gagan Gupta
Nov 8 at 11:25












Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
– Clyde T
Nov 8 at 11:39




Sorry sawa, i don't speak english .. And @GaganGupta thank you very much it works with 0 and 1 ! It was as simple as that .. big thanks !
– Clyde T
Nov 8 at 11:39












ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
– Gagan Gupta
Nov 8 at 11:41




ohh :D, I am glad it worked. Just check the database whether it is updating the correct values as true and false for 1 and 0.
– Gagan Gupta
Nov 8 at 11:41












@GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
– Clyde T
Nov 8 at 11:43




@GaganGupta Yes I check and 0 or 1 update my database correctly with true or false ! :) Thx !!!
– Clyde T
Nov 8 at 11:43












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










hidden_field behaves as a hidden text_field hence, it expects a string value. I would suggest you to pass a text value which you can consider false inside a controller.



either use values 0/1



OR



another way would be:



example:





def sign_up_params
params[:user][:member] = params[:user] && params[:user][:member] == '0' ? false : true
params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
end


you can handle this manually inside your controller.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206360%2fchange-boolean-value-with-hidden-field%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    hidden_field behaves as a hidden text_field hence, it expects a string value. I would suggest you to pass a text value which you can consider false inside a controller.



    either use values 0/1



    OR



    another way would be:



    example:





    def sign_up_params
    params[:user][:member] = params[:user] && params[:user][:member] == '0' ? false : true
    params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
    end


    you can handle this manually inside your controller.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      hidden_field behaves as a hidden text_field hence, it expects a string value. I would suggest you to pass a text value which you can consider false inside a controller.



      either use values 0/1



      OR



      another way would be:



      example:





      def sign_up_params
      params[:user][:member] = params[:user] && params[:user][:member] == '0' ? false : true
      params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
      end


      you can handle this manually inside your controller.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        hidden_field behaves as a hidden text_field hence, it expects a string value. I would suggest you to pass a text value which you can consider false inside a controller.



        either use values 0/1



        OR



        another way would be:



        example:





        def sign_up_params
        params[:user][:member] = params[:user] && params[:user][:member] == '0' ? false : true
        params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
        end


        you can handle this manually inside your controller.






        share|improve this answer












        hidden_field behaves as a hidden text_field hence, it expects a string value. I would suggest you to pass a text value which you can consider false inside a controller.



        either use values 0/1



        OR



        another way would be:



        example:





        def sign_up_params
        params[:user][:member] = params[:user] && params[:user][:member] == '0' ? false : true
        params.require(:user).permit(:name, :fullname, :email, :password, :password_confirmation, :member)
        end


        you can handle this manually inside your controller.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 11:39









        Gagan Gupta

        740317




        740317






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206360%2fchange-boolean-value-with-hidden-field%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check