logo
down
shadow

nested resources in devise


nested resources in devise

By : beta93
Date : November 22 2020, 10:38 AM
Hope that helps You probably want to pluralize the list resource and make the user resource singular:
code :
resource :user do
  resources :lists
end
@lists = current_user.lists


Share : facebook icon twitter icon
Rails 3 nested resources with users (Devise) structure

Rails 3 nested resources with users (Devise) structure


By : Micha Nanoucha
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can leave the users out of the path. Just include the devise_for :users on top of your routes without including it in your resources block.
A user has many topics and has many replies. Both topics and replies belong to a user.
Rails nested resources and devise

Rails nested resources and devise


By : parweb
Date : March 29 2020, 07:55 AM
I hope this helps . Mongoid will manage the document references and queries for you, just make sure to specify the association/relationship for each direction that you need (e.g., User has_many :notes AND Note belongs_to :user). Like ActiveRecord, it appears to be "smart" about the relations. Please do not manipulate the references manually, but instead let your ODM (Mongoid) work for you. As you run your tests (or use the rails console), you can tail -f log/test.log (or log/development.log) to see what MongoDB operations are being done by Mongoid for you and you can see the actual object references as the documents are updated. You can see how a relationship makes use of a particular object reference, and if you pay attention to this, the link optimization should become clearer.
The following models and test work for me. Details on the setup are available on request. Hope that this helps.
code :
class User
  include Mongoid::Document
  field :name

  has_many :notebooks
  has_many :notes
end

class Note
  include Mongoid::Document
  field :text

  belongs_to :user
  belongs_to :notebook
end

class Notebook
  include Mongoid::Document

  belongs_to :user
  has_many :notes
end
require 'test_helper'

class UserTest < ActiveSupport::TestCase

  def setup
    User.delete_all
    Note.delete_all
    Notebook.delete_all
  end

  test "user" do
    user = User.create!(name: 'Charles Dickens')
    note = Note.create!(text: 'It was the best of times')
    notebook = Notebook.create!(title: 'Revolutionary France')
    user.notes << note
    assert_equal(1, user.notes.count)
    user.notebooks << notebook
    assert_equal(1, user.notebooks.count)
    notebook.notes << note
    assert_equal(1, notebook.notes.count)
    puts "user notes: " + user.notes.inspect
    puts "user notebooks: " + user.notebooks.inspect
    puts "user notebooks notes: " + user.notebooks.collect{|notebook|notebook.notes}.inspect
    puts "note user: " + note.user.inspect
    puts "note notebook: " + note.notebook.inspect
    puts "notebook user: " + notebook.user.inspect
  end

end
Run options: --name=test_user

# Running tests:

user notes: [#<Note _id: 4fa430937f11ba65ce000002, _type: nil, text: "It was the best of times", user_id: BSON::ObjectId('4fa430937f11ba65ce000001'), notebook_id: BSON::ObjectId('4fa430937f11ba65ce000003')>]
user notebooks: [#<Notebook _id: 4fa430937f11ba65ce000003, _type: nil, user_id: BSON::ObjectId('4fa430937f11ba65ce000001'), title: "Revolutionary France">]
user notebooks notes: [[#<Note _id: 4fa430937f11ba65ce000002, _type: nil, text: "It was the best of times", user_id: BSON::ObjectId('4fa430937f11ba65ce000001'), notebook_id: BSON::ObjectId('4fa430937f11ba65ce000003')>]]
note user: #<User _id: 4fa430937f11ba65ce000001, _type: nil, name: "Charles Dickens">
note notebook: #<Notebook _id: 4fa430937f11ba65ce000003, _type: nil, user_id: BSON::ObjectId('4fa430937f11ba65ce000001'), title: "Revolutionary France">
notebook user: #<User _id: 4fa430937f11ba65ce000001, _type: nil, name: "Charles Dickens">
.

Finished tests in 0.018622s, 53.6999 tests/s, 161.0998 assertions/s.

1 tests, 3 assertions, 0 failures, 0 errors, 0 skips
Nested resources with devise

Nested resources with devise


By : Jimmy
Date : March 29 2020, 07:55 AM
This might help you This is my routes file. , Try this (HAML):
code :
- current_user.articles.each do |article|
  = article.name
Rails3 + Devise: When to nest resource in devise_for & nested resources

Rails3 + Devise: When to nest resource in devise_for & nested resources


By : XiaoleiWei
Date : March 29 2020, 07:55 AM
this will help , The following example:
code :
devise_for :users, :path => 'accounts'

resources :users do
    resources :orders
end
devise_for :users do 
   resources: somereosouce
end 
# Session routes for Authenticatable (default)
     new_user_session GET  /users/sign_in                    {:controller=>"devise/sessions", :action=>"new"}
         user_session POST /users/sign_in                    {:controller=>"devise/sessions", :action=>"create"}
 destroy_user_session GET  /users/sign_out                   {:controller=>"devise/sessions", :action=>"destroy"}

# Password routes for Recoverable, if User model has :recoverable configured
    new_user_password GET  /users/password/new(.:format)     {:controller=>"devise/passwords", :action=>"new"}
   edit_user_password GET  /users/password/edit(.:format)    {:controller=>"devise/passwords", :action=>"edit"}
        user_password PUT  /users/password(.:format)         {:controller=>"devise/passwords", :action=>"update"}
                      POST /users/password(.:format)         {:controller=>"devise/passwords", :action=>"create"}

# Confirmation routes for Confirmable, if User model has :confirmable configured
new_user_confirmation GET  /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
    user_confirmation GET  /users/confirmation(.:format)     {:controller=>"devise/confirmations", :action=>"show"}
                      POST /users/confirmation(.:format)     {:controller=>"devise/confirmations", :action=>"create"}
devise_for :users 

resource :users do 
   resource :foo_object
end 
class Users < ActiveRecord::Base
  has_many :foo_object
end

class FooObject < ActiveRecord::Base
  belongs_to :users
end
   resource :users do 
     resource :foo_object 
   end
Why are the nested resources for Devise authentication not working?

Why are the nested resources for Devise authentication not working?


By : Stuart D
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You have to add :operator_id to Devise's permitted parameters
Take a look here
code :
before_action :configure_permitted_parameters, if: :devise_controller?

  protected

    def configure_permitted_parameters
      devise_parameter_sanitizer.for(:sign_up) do |u|
        u.permit(:email, :password, :password_confirmation, :operator_id) #add :operator_id
      end
    end
Related Posts Related Posts :
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • One action in Rails controller sends no data back
  • Local data (JSON) in Middleman inside a different path than /data
  • How to pass numbers in an array into a SQL statement
  • ActiveAdmin - Allow non-logged-in users to view but not edit resources
  • How to refactor this Model logic in Rails
  • :readonly key of belongs_to method doesn't work
  • Create a new view in directory
  • Yaml value with a leading `!`
  • Rails admin show username instead of User #5
  • Can't start WEBrick with Byebug on
  • Failing Rspec test of a FactoryGirl object
  • engine yard No application found matching remotes:
  • Rails 4 sessions cookie is not set
  • How do I flush a class method in Rails 4 using memcached?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org