मैं रेल पर्यावरण पर रूबी के लिए नया हूं और अधिकांश समस्याओं को हल करने में सक्षम हूं, लेकिन मैं नहीं ढूंढ पा रहा हूं अभी तक इस समस्या का समाधान।रेल 4 और डिवाइसेज - उपयोगकर्ता का नाम डेटाबेस में जोड़ा नहीं जाता है जब नया उपयोगकर्ता
संदर्भ प्रदान करने के लिए:
- रेल (4.0.0)
- का उपयोग करते हुए वार्डन (1.2.3)
- का उपयोग वसीयत का उपयोग करना (3.0.0)
- rolify का उपयोग करना (3.2 .0)
- का उपयोग कैनकैन (1.6.10)
मेरे समस्या
जब मैं वसीयत के पंजीकरण के साथ एक नया उपयोगकर्ता sign_up। नाम: डेटाबेस में नाम फ़ील्ड नहीं जोड़ा जा रहा है। देखें सर्वर उत्पादन
उपयोगकर्ता मॉडल (एप्लिकेशन/मॉडल/user.rb)
: नाम attr_accessible में शामिल है।
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
end
उपयोगकर्ता नियंत्रक (एप्लिकेशन/नियंत्रक/users_controller.rb)।
मैंने रेल 4 के साथ रखने के लिए पैराम्स श्वेतसूची को जोड़ा है, लेकिन इससे समस्या हल नहीं हुई।
class UsersController < ApplicationController
before_filter :authenticate_user!
def index
authorize! :index, @user, :message => 'Not authorized as an administrator.'
@users = User.all
end
def show
@user = User.find(params[:id])
end
def update
authorize! :update, @user, :message => 'Not authorized as an administrator.'
@user = User.find(params[:id])
if @user.update_attributes(params[:user], :as => :admin)
redirect_to users_path, :notice => "User updated."
else
redirect_to users_path, :alert => "Unable to update user."
end
end
def destroy
authorize! :destroy, @user, :message => 'Not authorized as an administrator.'
user = User.find(params[:id])
unless user == current_user
user.destroy
redirect_to users_path, :notice => "User deleted."
else
redirect_to users_path, :notice => "Can't delete yourself."
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :remember_me)
end
end
वसीयत के नए पंजीकरण दृश्य (एप्लिकेशन/विचारों/वसीयत/पंजीकरण/new.html.erb)
<h2>Sign up</h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %>
<%= f.error_notification %>
<%= display_base_errors resource %>
<%= f.input :name, :autofocus => true %>
<%= f.input :email, :required => true %>
<%= f.input :password, :required => true %>
<%= f.input :password_confirmation, :required => true %>
<%= f.button :submit, 'Sign up', :class => 'btn-primary' %>
<% end %>
<%= render "devise/shared/links" %>
आवेदन नियंत्रक (एप्लिकेशन/नियंत्रक/application_controller.rb)
मैंने मजबूत मानकों के संबंध में निर्देशों का पालन किया है, और Devise
से आलसी आदमी के दृष्टिकोण को शामिल किया है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 :configure_permitted_parameters, if: :devise_controller?
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:name, :email) }
end
end
नया उपयोगकर्ता बनाते समय सर्वर आउटपुट।
Started POST "/users" for 127.0.0.1 at 2013-07-16 15:31:20 +1000
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"TYp9xOgtdKJI62rUddU7EE1C7FDF5qnmWgGENluzaWk=", "user"=>{"name"=>"John Smith", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: name
(0.1ms) begin transaction
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
Binary data inserted for `string` type on column `encrypted_password`
SQL (0.3ms) INSERT INTO "users" ("created_at", "email", "encrypted_password", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Tue, 16 Jul 2013 05:31:20 UTC +00:00], ["email", "[email protected]"], ["encrypted_password", "$2a$10$kMfZLiBm6md0zoWXd0esjO/IRHBC72444ABDKcXVhPa6mCco9pIJu"], ["updated_at", Tue, 16 Jul 2013 05:31:20 UTC +00:00]]
(17.0ms) commit transaction
(0.1ms) begin transaction
Binary data inserted for `string` type on column `last_sign_in_ip`
Binary data inserted for `string` type on column `current_sign_in_ip`
SQL (0.4ms) UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "last_sign_in_ip" = ?, "current_sign_in_ip" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = 3 [["last_sign_in_at", Tue, 16 Jul 2013 05:31:20 UTC +00:00], ["current_sign_in_at", Tue, 16 Jul 2013 05:31:20 UTC +00:00], ["last_sign_in_ip", "127.0.0.1"], ["current_sign_in_ip", "127.0.0.1"], ["sign_in_count", 1], ["updated_at", Tue, 16 Jul 2013 05:31:20 UTC +00:00]]
(1.1ms) commit transaction
Redirected to http://0.0.0.0:3000/
Completed 302 Found in 94ms (ActiveRecord: 19.0ms)
मेरे निष्कर्ष
इस सब के बाद मेरा मानना है कि समस्या में वसीयत के registration_controller निहित है, लेकिन मैं वास्तव में यकीन है कि नियंत्रक तक पहुँचने और इस सुधार के बारे में जाने के लिए कैसे, या यदि नहीं कर रहा हूँ यह वह जगह है जहां वास्तव में समस्या है। मुझे उम्मीद है कि यह कुछ आसान है और मैंने इसे अभी अनदेखा कर दिया है।
यदि कोई इस समस्या में भाग लेता है या स्थिति पर कुछ प्रकाश डाल सकता है, तो इसकी सराहना की जाएगी।
चीयर्स।
bundle open devise
यदि आप मानक वसीयत नियंत्रक ओवरराइड करने के लिए की जरूरत है, तो आप से नियंत्रक को कॉपी करके ऐसा कर सकते हैं:
आप मजबूत पैरा और attr_accessible दोनों का उपयोग क्यों करते हैं? –
मैंने मूल ऐप बनाने के लिए स्टार्टरैप जनरेटर का उपयोग किया, इसमें attr_accessible लाइनें शामिल थीं, और रेल के लिए नया होने के कारण, अब तक मुझे कोई बेहतर जानकारी नहीं मिली - इस समस्या के माध्यम से मजबूत पैरामीटर के बारे में सीखा। अंतर्दृष्टि के लिए – 7sunami