spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Associating current_user id to imported contacts list


Okey, based on your given information you can do the following to add the current_user_id to your contact.

In your ContactImportController

   .........

  def create
    @contact_import =
ContactImport.new(contact_params)
    @contact_import.user_id = current_user.id
    if @contact_import.save
      redirect_to contacts_path, notice: "Imported
contacts successfully."
    else
      render :new
    end
  end

  private

  def contact_params
    params.require(:contact_import).permit(:file)
  end

  .........

In your contact_import.rb file

 def load_imported_contacts
   spreadsheet = open_spreadsheet
   header = spreadsheet.row(1)
  (2..spreadsheet.last_row).map do |i|
  row = Hash[[header,
spreadsheet.row(i)].transpose]
  contact = Contact.find_by_id(row["id"]) ||
Contact.new
  contact.attributes =
row.to_hash.slice('first_name', 'last_name',
'mobile', 'email', 'info')
  contact.user_id = self.user_id # this should
work!
  contact
end

end

As you didn't mention where the Contact#load_imported_contacts either called in any before_save or before validation callback or not. But the way I mentioned the the current_user.id should be initialized to that contact model while persisting the data to user_id field. I hope this should be enough to solve your problem.

Thanks!


Categories : Ruby On Rails

Related to : Associating current_user id to imported contacts list
What is the best way to create a parent/master entry in a DJANGO CRUD database app and then add associating data fields to the parent/master?
No. You don't need multiple barcode models. The fact that you have a ForeignKey from barcode to hardware already allows you to have multiple barcodes for each hardware: a ForeignKey defines a many-to-one relationship. Also, it doesn't make any sense to name the foreignkey after the model it is in: it needs to be named for the model it is pointing to, ie hardware. Finally, don't prefix your field n

Categories : Python
C# EWS copy contacts to a mailbox
You can use Impersonation like this ExchangeUserData exchangeUserData = new ExchangeUserData(); exchangeUserData.Username = "c-sharp"; exchangeUserData.Password = "c-sharp"; // c-sharp's Password ExchangeService service = Service.ConnectToServiceWithImpersonation(exchangeUserData, impersonatedUserPrincipal); Contact contact = new Contact(service); // Specify the name and how the contact should

Categories : C#
The Cordova Contacts API is inaccessible
Read the following links for phonegap/cordova project. http://thejackalofjavascript.com/phonegap-3-cli-setup-mac-windows/ http://coenraets.org/blog/cordova-phonegap-3-tutorial/ http://teusink.blogspot.in/2013/07/guide-phonegap-3-android-windows.html http://sdk.revmobmobileadnetwork.com/phonegap_cordova.html http://docs.phonegap.com/en/3.5.0/guide_platforms_android_index.md.html#Android%20Plat

Categories : Android
How to test cordova contacts plugin with CADT or inside CDE?
Probably. You are right. You can file an issue to https://github.com/MobileChromeApps/chrome-app-developer-tool

Categories : Cordova
Sugarcrm: How to filter the accounts according to the type in a relationship field from contacts?
I edited the custom record view of accounts i.e. record.php and in the reseller field added following to array: filter_populate' => array ( 'account_type_c' => 'Resellers', ), Also, use the link for further reading. http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_7.5/20_UI_Model/30_Views/05_Filters/ Regards

Categories : Javascript
Recently Add
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
Why ActiveModel::ForbiddenAttributesError error?
How can i track the issue in production RAILS
Cannot install spree gem - ERROR: invalid gem: package is corrupt
Why are the nested resources for Devise authentication not working?
Rails Devise - how to open access to the site root
Rails: respond_with the same template for two methods
rails with postgresl database "role postgres does not exist"
Instance variable in Rails helper not set
Monkey patch rails 3.2 rake task
Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel
undefined method `attachments' for nil:NilClass
Memory usage increase with Ruby 2.1 versus Ruby 2.0 or 1.9
Can a Rails app be deployed without using Heroku Toolbelt? If so, how?
Enable random access to collection with MongoDB
libmysqlclient-dev installation fails
undefined method `name' for nil:NilClass. Can't find @followed.name but @followed is set
Allowing an arbitrary domain and subdomain in session_store.rb
Pushmeup Gem - Can't send push notifications in Active Admin model
Rails console does not start
GitHub Import: Could not locate Gemfile
AWS::S3::PermanentRedirect in SongsController#index "The bucket you are attempting to access must be addressed using the specified endpoint"
automatically create ActiveRecord parent for association
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.