Vote count:
0
I have an main app and a rails engine, and now I've created Views and Controllers for a Model that exists inside the rails engine.
My rake routes results is:
[bruno@chp main-app]$ rake routes
notificationss /notificationss notificationss::Engine
notificationss_messages GET /notifications/messages(.:format) notificationss/messages#index
POST /notifications/messages(.:format) notificationss/messages#create
new_notifications_message GET /notifications/messages/new(.:format) notifications/messages#new
edit_notifications_message GET /notifications/messages/:id/edit(.:format) notifications/messages#edit
notifications_message GET /notifications/messages/:id(.:format) notifications/messages#show
PATCH /notifications/messages/:id(.:format) notifications/messages#update
PUT /notifications/messages/:id(.:format) notifications/messages#update
DELETE /notifications/messages/:id(.:format) notifications/messages#destroy
But I can't use the same namespace engine to declare the routes, and it if I do this, I got many errors:
1) Notifications::MessagesController GET #index assigns all the messages as @messages
Failure/Error: get :index
ActionView::Template::Error:
undefined local variable or method `new_notifications_message_url' for #<#<Class:0x00000005ad9120>:0x00000005ac2a88>
# ./app/views/notifications/messages/index.html.slim:5:in `_app_views_notifications_messages_index_html_slim__2090168882652255551_47327940'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/actionview-4.2.0/lib/action_view/template.rb:145:in `block in render'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `block in instrument'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `instrument'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/actionview-4.2.0/lib/action_view/template.rb:333:in `instrument'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/actionview-4.2.0/lib/action_view/template.rb:143:in `render'
# /home/bruno/.rvm/gems/ruby-2.2.1/gems/actionview-4.2.0/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
Controller Test:
RSpec.describe Notifications::MessagesController, type: :controller do
render_views
let(:valid_attributes) { attributes_for :notifications_message }
let(:invalid_attributes) { attributes_for :invalid_notifications_message }
describe 'GET #index' do
it 'assigns all the messages as @messages' do
message = create :notifications_message, valid_attributes
get :index
expect(assigns(:messages)).to include(message)
end
it 'success if path exists' do
get :index
expect(response).to have_http_status(:success)
end
end
#... omitted
end
My Controller:
class Notifications::MessagesController < ApplicationController
before_action :set_message, only: [:edit, :update, :show, :destroy]
def index
@messages = Notifications::Message.all
respond_with(@messages)
end
#... omitted
end
If I change to any other name instead of 'notifications', It works. How I can share this namespace?!
asked 1 min ago
Could I share the Rails Engine namespace with the Main Application?
Aucun commentaire:
Enregistrer un commentaire