0

I'm trying create a application with both active and neo4j models, and I want to use the following for my neo4j models:

module Neo
  class Usernode
    include Neo4j::ActiveNode
    property :first_name, type: String
    property :last_name, type: String
    property :address, type: String
  end
end

And use them in my controller as the following:

class UsernodesController < ApplicationController

  def index
    @usernodes = Neo::Usernode.all
  end

in my routes.db file I have the following route for this:

  Rails.application.routes.draw do
      resources :usernodes, path: '/usernodes'
    end

The problem with this is that it only produces routes that has '/neo/usernodes/', and I only want to use routes with '/usernodes/'.

Is it possible to product only '/usernodes/'? If yes, how can I do that?

then if I use in routes.db:

resources :usernodes, path: '/usernodes'

I get the following error:

Processing by UsernodesController#new as HTML
Rendered usernodes/_form.html.erb (12.2ms)   
Rendered usernodes/new.html.erb within layouts/application (12.7ms)
Completed 500 Internal Server Error in 15ms 
ActionView::Template::Error (undefined method 'neo_usernodes_path' for
#<#<Class:0x0000000788e968>:0x000000089f3c08>):
    1: <%= form_for(@usernode) do |f| %>
    2:   <% if @usernode.errors.any? %>
    3:     <div id="error_explanation">
    4:       <h2><%= pluralize(@usernode.errors.count, "error") %> prohibited this usernode from being saved:</h2>

this is my routes:

 Prefix Verb   URI Pattern                   Controller#Action
        users GET    /users(.:format)              users#index
              POST   /users(.:format)              users#create
     new_user GET    /users/new(.:format)          users#new
    edit_user GET    /users/:id/edit(.:format)     users#edit
         user GET    /users/:id(.:format)          users#show
              PATCH  /users/:id(.:format)          users#update
              PUT    /users/:id(.:format)          users#update
              DELETE /users/:id(.:format)          users#destroy
    usernodes GET    /usernodes(.:format)          usernodes#index
              POST   /usernodes(.:format)          usernodes#create
 new_usernode GET    /usernodes/new(.:format)      usernodes#new
edit_usernode GET    /usernodes/:id/edit(.:format) usernodes#edit
     usernode GET    /usernodes/:id(.:format)      usernodes#show
              PATCH  /usernodes/:id(.:format)      usernodes#update
              PUT    /usernodes/:id(.:format)      usernodes#update
              DELETE /usernodes/:id(.:format)      usernodes#destroy
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Isn't that route line surrounded by `namespace :neo` block? – D-side Nov 25 '14 at 11:20
  • not `neo_usernodes_path` as you can see in routes helper should `new_usernode_path` for `new` action and `usernodes_path` for `index` action – Roman Kiselenko Nov 25 '14 at 11:51
  • its probably mispelling, but I can't seem to find it. Anyway thx for your guys help :) – James Ramsfield Nov 25 '14 at 12:00
  • @JamesRamsfield you add `module` option or use my approach(fix `_path` helper)? i just want understand where a problem. – Roman Kiselenko Nov 25 '14 at 12:02
  • well, I tried with `resources :usernodes, module: 'neo', path: 'usernodes'` and get a different error: `uninitialized constant Neo::UsernodesController` and the fix with path I dont simply know what you mean sorry...I think I did that problably..I can't find any `neo_usernode_path` so that's good – James Ramsfield Nov 25 '14 at 12:11
  • 1
    you cant find it because rails put this by default in to `<%= form_for(@usernode) do |f| %>`, i call it stupid rails magic. Fix form to `<%= form_for(@usernode, url: new_usernode_path) do |f| %>` – Roman Kiselenko Nov 25 '14 at 12:15
  • and change `@usernode` to `:usernode` in form. – Roman Kiselenko Nov 25 '14 at 12:21
  • Hey, I got further thx, but now I for some weird reason get the following problem, when i try to create a new user: `No route matches [POST] "/usernodes/new"` . I'm still using `resources :usernodes, path: '/usernodes'` in routes.db – James Ramsfield Nov 25 '14 at 12:31
  • I tried to change form to `<%= form_for(:usernode, url: new_usernode_path) do |f| %>`, but I still get get a `No route matches [POST] "/usernodes/new"` – James Ramsfield Nov 25 '14 at 12:37
  • @JamesRamsfield i suggest you read [Getting Up and Running](http://guides.rubyonrails.org/getting_started.html#getting-up-and-running). For now you have problem with routes and controller actions. – Roman Kiselenko Nov 25 '14 at 12:41
  • hehe good enough, thx for help ;) – James Ramsfield Nov 25 '14 at 12:47

1 Answers1

0

Please try below:

resources :usernodes, module: 'neo', path: 'usernodes'
Mehul Gurjar
  • 284
  • 1
  • 7