Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 848913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:01:04+00:00 2026-05-15T07:01:04+00:00

Right now I’m building a project management app in rails, here is some background

  • 0

Right now I’m building a project management app in rails, here is some background info:

Right now i have 2 models, one is User and the other one is Client. Clients and Users have a one-to-one relationship (client -> has_one and user -> belongs_to which means that the foreign key it’s in the users table)

So what I’m trying to do it’s once you add a client you can actually add credentials (add an user) to that client, in order to do so all the clients are being displayed with a link next to that client’s name meaning that you can actually create credentials for that client.

What i can’t figure it out how to do is, that if you actually have credentials in the database (meaning that there’s a record in the users table with your client id) then don’t display that link.

Here’s what i thought that would work

<% for client in @client%>
     <h5>
         <h4><%= client.id %></h4>
         <a href="/clients/<%= client.id %>"><%= client.name %></a>
          <% for user in @user %>
            <% if user.client_id = client.id %>
                <a href="/clients/<%= client.id %>/user/new">Credentials</a>
            <%end%>
          <% end %>
     </h5>
<% end %> 

And here’s the controller:

def index
@client = Client.find_all_by_admin(0)
@user = User.find(:all)
end

but instead it just puts the link the amount of times per records in the user table. Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:01:05+00:00Added an answer on May 15, 2026 at 7:01 am

    You can do the following

    # controller
    def index
       @clients = Client.find_all_by_admin(0, :include => :user)
    end
    
    # view
    <% @clients.each do |client| %>
       <h5>
          <h4><%= client.id %></h4>
          <%= link_to client.name, {:action => 'show', :id => client.id} %>
    
          <% if client.user.blank? %>
             <%= link_to "Credentials", 
                {:controller => 'user', :action => 'new', :client_id => client.id} %>
          <% end %>
       </h5>
    <% end %> 
    

    Edit

    Better solution, getting in the controller only the clients who doesn’t have a user yet:

    # model
    class Client < ActiveRecord::Base
       has_one :user
    
       named_scope :without_user,
          :conditions => "id NOT IN ( SELECT client_id FROM users )"
    end
    
    # controller 
    @clients = Client.without_user.find_all_by_admin(0)
    
    # view
    <% @clients.each do |client| %>
       <h5>
          <h4><%= client.id %></h4>
          <%= link_to client.name, {:action => 'show', :id => client.id} %>
          <%= link_to "Credentials", 
                {:controller => 'user', :action => 'new', :client_id => client.id} %>
       </h5>
    <% end %> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have some TabItems in my App which are implicitly styled. I
Right now I have some troubles. I'm finding a way to solve one problem.
Right now, I have three models Post, Comment and User (using Devise ) associated
Right now, I miss quite some issues for my project hosted on GitHub. I
Right now I have two fields for cost. One for dollars and one for
Right now I'm building a website. Here's the link: http://theoew.uuuq.com/home/ This probably won't make
Right now, I have configuration setting for morphia talks to one MongoDB from Play!.
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I have an SSIS package that runs every morning and gives me
Right now, I have two Eclipse projects - they both use Maven 2 for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.