So I’m currently trying to map my building’s network with a RoR implementation. I have a good floor plan set up, and I’ve created the switch objects for it as well. Eventually, the switches will have many jacks, and each jack will map one-to-one with a room number.
Currently everything is working perfectly through the floors and switches until I try to show the switch individually. I’m trying to do this by using the show method in a separate controller. Originally the floor controller was in charge, but now I want the switch controller to be.
Here is my partial switch code (apps/views/switch/_switch.html.erb):
<p>
<%= switch.title %>
<%= link_to 'show', :controller => "switches", :action => 'show' %>
<%= link_to 'Destroy', [switch.floor, switch],
:confirm => 'Are you sure?',
:method => :delete %>
</p>
Here is my show method (apps/controllers/switches_controller.rb):
...
def show
@floor = Floor.find(params[:floor_id])
@switch = @floor.switches.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @switch }
end
end
...
When I do not tag the switch controller in the partial, whenever I click show the link acts as a link back to the same page…basically just a refresh. When I do tag the switch controller I get the ‘ No route matches [GET] “/assets” ‘ error.
I’ve tried MULTIPLE different syntaxes and nothing has worked. If anyone can help me out I will be very thankful!!
Please let me know if it’s necessary to post more of my code and I will.
You can run ‘rake routes‘ command to list all available routing options and recommend you to use url/path rather than specifying controller and actions for individual links.
I assume that you have setup nested route for floor and switch, then to obtain this URL i.e
you can use
<%= link_to "Switch", floor_switch_path(switch.floor, switch) %>