ruby - I have somehow broken my Rails app - the dreaded NoMethod Error -
the error message nomethoderror in circuit#update undefined method 'network_address' nil:nilclass , related line in view:
<td><%= logical_interface.subnet.network_address %></td> everything working earlier , i've managed break somehow when restarted local server.
update.rhtml
<table id="logical_interfaces"> <% @logical_interfaces.each |logical_interface| %> <tr id="logical_interface_<%= logical_interface.id %>"> <td><%= logical_interface.description %></td> <td><%= logical_interface.subnet.network_address %></td> <td><%= logical_interface.bandwidth %></td> </td> </tr> <% end %> </table> logical_interface.rb
belongs_to :subnet belongs_to :circuit subnet.rb
belongs_to :logical_interface belongs_to :circuit circuit.rb
has_many :subnets has_many :logical_interfaces circuit_controller.rb
the crud being done inside controller of model because main object else runs off.
def update .... if params[:id] @circuit = circuit.find(params[:id]) end @logical_interfaces = logicalinterface.find_all_by_circuit_id(@circuit.id) .... end as common bugs, i'll bet silly genuinely can't work out myself appreciate answers. have feeling it's relationships have been defined between models wrong.
subnet nil logical_interface. either add validation in logicalinterface model:
validates_presence_of :subnet or display network_address if subnet present.
<td><%= logical_interface.subnet.try(:network_address) %></td>
Comments
Post a Comment