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 6356945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:04:09+00:00 2026-05-24T23:04:09+00:00

I’ve got three tables which all join into one table. Here is the code:

  • 0

I’ve got three tables which all join into one table. Here is the code:

class App < ActiveRecord::Base
  has_many :app_servers
  has_many :servers, :through => :app_servers
  has_many :environments, :through => :app_servers
end

class Server < ActiveRecord::Base
  has_many :app_servers
  has_many :apps, :through => :app_servers
  has_many :environments, :through => :app_servers
end

class Environment < ActiveRecord::Base
  has_many :app_servers
  has_many :apps, :through => :app_servers
  has_many :servers, :through => :app_servers
end

class AppServer < ActiveRecord::Base
  belongs_to :app
  belongs_to :server
  belongs_to :environment
end

I’ve already used scaffold for the App and Server model and can access them, but when I created a scaffold for AppServer and tried accessing the index page, it gives me this error:

No route matches {:action=>"show", :controller=>"app_servers", :id=>#<AppServer app_id: 3, server_id: 1, environment_id: 2>}

I believe the reason for the error is because when I created the AppServer table, I specified that :id => false.

So what I’m really trying to do, is just have the create page, which then allows me to map currently saved Servers, with currently saved Application to a specific environment.
Any ideas on how I can overcome this problem?

Also, is it wrong for my join model to not have an ID, as it was originally a has_and_belongs_to_many model?

Thanks in advance

Edit Here is the index.html.erb file:

<h1>Listing app_servers</h1>

<table>
  <tr>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @app_servers.each do |app_server| %>
  <tr>
<td><%= app_server%></td>
    <td><%= link_to 'Show', app_server %></td>
    <td><%= link_to 'Edit', edit_app_server_path(app_server) %></td>
<td><%= link_to 'Destroy', app_server, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New App server', new_app_server_path %>

And also the app_servers_controller.rb file:

class AppServersController < ApplicationController
  # GET /app_servers
  # GET /app_servers.xml
  def index
    @app_servers =AppServer.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @app_servers }
    end
  end

  # GET /app_servers/1
  # GET /app_servers/1.xml
  def show
    @app_server = AppServer.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @app_server }
    end
  end

  # GET /app_servers/new
  # GET /app_servers/new.xml
  def new
    @app_server = AppServer.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @app_server }
    end
  end

  # GET /app_servers/1/edit
  def edit
    @app_server = AppServer.find(params[:id])
  end

  # POST /app_servers
  # POST /app_servers.xml
  def create
    @app_server = AppServer.new(params[:app_server])

    respond_to do |format|
      if @app_server.save
        format.html { redirect_to(@app_server, :notice => 'App server was successfully     created.') }
        format.xml  { render :xml => @app_server, :status => :created, :location =>     @app_server }
      else
    format.html { render :action => "new" }
        format.xml  { render :xml => @app_server.errors, :status =>     :unprocessable_entity }
      end
    end
  end

  # PUT /app_servers/1
  # PUT /app_servers/1.xml
  def update
    @app_server = AppServer.find(params[:id])

    respond_to do |format|
      if @app_server.update_attributes(params[:app_server])
        format.html { redirect_to(@app_server, :notice => 'App server was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @app_server.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /app_servers/1
  # DELETE /app_servers/1.xml
  def destroy
    @app_server = AppServer.find(params[:id])
    @app_server.destroy

    respond_to do |format|
      format.html { redirect_to(app_servers_url) }
      format.xml  { head :ok }
    end
  end
end
  • 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-24T23:04:10+00:00Added an answer on May 24, 2026 at 11:04 pm

    Ok. The simplesst solution here is to return id back. Or you should rewrite some standart routes like

    get '/app_servers/show', :to => "app_servers#show", :as => :app_server
    

    and remove fetching by id from controllers.

    I mean – return IDS back – that’s easiear

    UPD

    Fast and dirty solution here is to add to AppServer model this small method:

    def to_param
      "#{environment_it}_#{app_id}_#{server_id}"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.