Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I post a client ID in a different controllers view?

Spohnz asked in Rails

Hello, I am so very new to Rails that my question might seem odd. But I will try to be as explicit as possible.
I have a controller named clients, It shows

<%= @client.client_identifier %> - <%= @client.client_name %>

in the view that renders a clients ID and a Name. I click on "new Appliance" for this client and have it take me to a new controller. I would like to in the new controller view to show the ID of the client so I can eventually concatenate to it and save it as a hostname.
Any help on how I can get <%= @client.client_identifier %> to show up in my "new appliance" page?

Reply

Hey Spohnz,

Assuming you have an appliance controller, you might want to add @client in appliance_controller.rb under the index or show methods. e.g.

class ApplianceController < ApplicationController
    def index
        @appliance = Appliance.all
        @client = Client.all
    end
end

But I'm also just learning too, and whilst the above works, someone else might have another suggestion.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.