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
ruby-on-rails
|
show 1 more comment
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
ruby-on-rails
Please you English punctuation when writing in English.
– sawa
Nov 8 at 11:06
1
instead of passing values astrue/false
. Try passing it as0/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
|
show 1 more comment
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
ruby-on-rails
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
ruby-on-rails
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 astrue/false
. Try passing it as0/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
|
show 1 more comment
Please you English punctuation when writing in English.
– sawa
Nov 8 at 11:06
1
instead of passing values astrue/false
. Try passing it as0/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
|
show 1 more comment
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 8 at 11:39
Gagan Gupta
740317
740317
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 as0/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