Wprowadziłem trzy inne pola w opracowaniu innychnastępnie e-mail n hasło do rejestracji.Po wprowadzeniu danych, kiedy klikam Zarejestruj się, przyjmuje pustą wartość i wyświetla komunikat o błędzie. jeśli usunę walidację, a następnie wprowadzę dane, to akceptuje rejestrację, ale kiedy widzę w bazie danych, pokazuje wartości null. tylko zajmuje e-mail n hasło
mój kontroler aplikacji to
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :update_sanitized_params, if: :devise_controller?
def update_sanitized_params
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:name, :surname, :age)}
end
end
mój model kontrolera to
class Twk < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates_presence_of :name, :message => "is must."
validates_presence_of :age, :message => "is needed.", value: {minimum: 1}
end
co mam zrobić, proszę zasugerować ...
moja forma
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :name %><br />
<%= f.text_field :name %></div>
<div><%= f.label :surname %><br />
<%= f.text_field :surname %></div>
<div><%= f.label :age %><br />
<%= f.number_field :age %></div>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
ostatni mój links.erb jest
<%- if controller_name != "sessions" %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != "registrations" %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != "passwords" && controller_name != "registrations" %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != "confirmations" %>
<%= link_to "Didn"t receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != "unlocks" %>
<%= link_to "Didn"t receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
Odpowiedzi:
0 dla odpowiedzi № 1Czy sprawdziłeś swoje dzienniki pod kątem rozszerzenia Unpermitted parameters
wiadomość?
Jeśli chcesz użyć {|u| u.permit(:name, :surname, :age)}
, musisz określić każdy parametr, a nie tylko dodatkowe. Jeśli chcesz dodać dodatkowe parametry, nie wymieniając ich wszystkich, możesz użyć formatu takiego jak devise_parameter_sanitizer.for(:sign_up) << :name
.