PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

"add from existing" missing in a belongs_to/has_many relationship #737

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Two model: Switch and Networkrack, the first belongs_to the second, and
the second has_many of the first. Following definition and schema.rb.

#[...]/app/model/networkrack.rb
class Networkrack < ActiveRecord::Base
  has_many :switches
  def to_label
    "#{nome}"
  end
end

#[...]/app/model/switch.rb
class Switch < ActiveRecord::Base
  belongs_to :networkrack
  def to_label
    "#{nome}"
  end
end

#[...]/db/schema.rb
ActiveRecord::Schema.define(:version => 20100316155957) do

  create_table "networkracks", :force => true do |t|
    t.string   "inventario"
    t.string   "nome"
    t.string   "edificio"
    t.string   "piano"
    t.string   "stanza"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "switches", :force => true do |t|
    t.string   "inventario"
    t.string   "nome"
    t.string   "ip"
    t.boolean  "mgmt"
    t.text     "note"
    t.integer  "networkrack_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end

2. Configured (hopefully properly) routes.rb and the default layout:

#[...]/config/routes.rb
ActionController::Routing::Routes.draw do |map|
  map.resources :switch, :active_scaffold => true

  map.resources :networkrack, :active_scaffold => true
[...]

#[...]/app/views/layouts/application.html.erb 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.d\
td">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type"  content="text/html;charset=UTF-8" />
    <title>Inventario Infrastruttura</title>
    <%= stylesheet_link_tag 'scaffold' %>
    <%= javascript_include_tag :defaults %>
    <%= active_scaffold_includes %>
  </head>
[...]

3. And controllers:

#[...]/app/controllers/switches_controller.rb
class SwitchesController < ApplicationController
  active_scaffold :switches
end

#[...]/app/controllers/networkracks_controller.rb
class NetworkracksController < ApplicationController
  active_scaffold :networkracks
end

What is the expected output? What do you see instead?

The expected output is an "add from existing" link in the networkrack
controller, but what I have is just "Create New" and "Search". The same
apply to the switch controller.

What version (or revision) of the product are you using?

rails 2.3.5

active_scaffold 1.2RC1 (script/plugin install
git://github.com/activescaffold/active_scaffold.git)

Thanks in advance
Davide Vaghetti
--
NOC Faculty of Engineeer 
University of Pisa 
Italy

Original issue reported on code.google.com by davide.v...@gmail.com on 17 Mar 2010 at 12:58

GoogleCodeExporter commented 9 years ago
In create and update forms of networkrack you will get a select box to choose
switchs without networkrack, if you don't have switchs without networkrack you 
won't
get any select box to add existing switch.

In create and update forms of switch you won't get add existing networkrack, if 
you
want to choose an existing networkrack instead of creating a new one, use
config.columns[:networkrack].form_ui = :select

Original comment by sergio.c...@gmail.com on 18 Mar 2010 at 8:21

GoogleCodeExporter commented 9 years ago
I was wrong, in create and update forms of switch you will get a select box to
choose a networkrack.

Also, I see now you are using master branch. There was a bug in master branch 
which
I have fixed now. Anyway, master branch has incompatibilities with previous 
version,
if you have updated from a previous version you will have to check your
authorized_for methods in your models, and your form and search overrides in 
your
helpers. Also, some AS plugins won't work with master branch.

Original comment by sergio.c...@gmail.com on 18 Mar 2010 at 8:32