ruby on rails - Linking models created using Devise + Activeadmin -
ruby on rails - Linking models created using Devise + Activeadmin -
i have 2 models listing , profile configured active admin. model profile generated using devise. have established has 1 relationship between them. want create scheme in each new listing, profile automatically created , linked. (imagine airbnb in seller can have 1 listing , cannot rent) linking should both valid in activeadmin , when user logins app. how should approach this.
side note: model profile not registerable. using through activeadmin of import 1 time listing , profile created superuser, can send login details person , can login view listing.
ps: rails newbie here! easier methods,tutorials or directions appreciated , if in or near london thanked beer.
for has_one relationship please see: http://guides.rubyonrails.org/association_basics.html#the-has-one-association
if want create profile when creating listing, can activeadmin's create controller of listing:
the code should this: (put in app/admin/listing.rb)
controller def create # create profile. @profile = profile.new # create listing , connect profile it. @listing = listing.create(permitted_params[:name]) @listing.profile = @profile create! |success, failure| succes.html { redirect_to admin_dashboard_path} # or whatever path. end end end
ruby-on-rails ruby-on-rails-4 devise activeadmin has-one
Comments
Post a Comment