How to display data using a namespaced controller rails 5.2

I have an admin namespace with items as a resource in it:

namespace :admin do
  resources :items
end

My items controller located in app/controllers/admin/ looks like this:

module Admin
  class ItemsController < ApplicationController
    def show             
    end

    private

    def set_item
      @item = Item.find(params[:id])
    end
  end
end

The problem I have is displaying the data in a show view: admin/items#show

it seems like since I have an admin namespace I cant display the data like I used to before I started trying out namespaces and scopes.

<p>
  <strong>Tittle:</strong>
  <%= @item.tittle %>
</p>

<p>
  <strong>Desciption:</strong>
  <%= @item.description %>
</p>

<!-- More item attributes -->

There error I get is:

undefined method `tittle' for nil:NilClass

Your show method does not set @item to anything.

Try

def show
  @item = Item.find(params[:id])
end

ruby on rails, Your routes are slightly wrong. You need to reference the subdomain in the link_to : <% @cars.each do |car| %> <%= link_to "Show", admin_car_path(id,  1.5 rails dbconsole. rails dbconsole figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL (including MariaDB), PostgreSQL, and SQLite3.

You already have a method set_item defined in your controller, but you haven't called it anywhere for your show action. Add a before_action like below:

module Admin
  class ItemsController < ApplicationController
    before_action :set_item, only: [:show]

    def show             
    end

    private

    def set_item
      @item = Item.find(params[:id])
    end
  end
end

Rails Routing from the Outside In, Rails Routing from the Outside InThis guide covers the user-facing features of the request is dispatched to the patients controller's show action with { id: '17' } By convention, each action also maps to a specific CRUD operation in a database. If you need to use a different controller namespace inside a namespace block  Does anyone use namespaced models? I thought it would be helpful for me to use namespaced models to organize my models better, but I've run into nothing but problems (I'm on Rails 4). I found a bunch of posts saying how unreliable they are, but they're all old (around the Rails 2 days).

You aren’t calling set_item anywhere. Either call that method directly in the show method, or call it in a before action by putting the following above the show method

before_action :set_item, only: :show

Action Controller Overview, How to use Action Controller's built-in HTTP authentication. It makes the model data available to the view so it can display that data to the user, and it saves or  Steps to reproduce create a mountable engine tickets in this engine rails g controller api/v1/tickets it should create controller that looks like require_dependency "tickets/application_controller" module Tickets class Api::V1::TicketsCo

rails routes is break after namespace routing resources jsonapi , GitHub is home to over 50 million developers working together to host and review code, My Rails application is rails-5.2.1 version the same way the example is showing, then routing access, create controller and resources. I choose a namespace because the json data access is separate from html data  All controllers in Rails have the send_data and the send_file methods, which will both stream data to the client. send_file is a convenience method that lets you provide the name of a file on the disk and it will stream the contents of that file for you. To stream data to the client, use send_data:

DRY Off Your Rails Code with ActiveSupport::Concerns, One of Rails' best conventions for DRYing up your code is ActiveSupport::​Concern. Kingsley to just admins), and the other will be in the conventional Rails namespace. After seeing how it works for controllers, I'll show you how to use collapsed" data-toggle="collapse" data-target="#navbar-collapse"  3.7 Controller Namespaces and Routing. Rails allows you to group your controllers into namespaces by saving them in folders underneath app/controllers. The :controller option provides a convenient way to use these routes. For example, you might have a resource whose controller is purely for admin users in the admin folder:

How To Create Nested Resources for a Ruby on Rails Web App , A firm grounding in the model-view-controller (MCV) architectural pattern, which This application already has a model for handling shark data, but you will add a This tutorial uses Ruby 2.5.1, rbenv 1.1.2, and Rails 5.2.3. Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred resourceful style or the match method. How to declare route parameters, which are passed onto controller actions. How to automatically create paths and

Comments
  • Why is @item nil? And, what are tittle and Desciption?