Microsoft
Software
Hardware
Network
Question : In Ruby on Rails, how do I create links to other views that will display the correct results from a related table
My Rails project currently has 6 models:
city_link - belongs_to :cities
city - belongs_to :states, has_many :city_links
county_link - belongs_to :counties
county - belongs_to :states, has_many :county_links
state_link - belongs_to: states
state - has_many :counties, has_many :cities, has_many :state_links
There are tables in the database corresponding to each of these models. There are lots of many-to-one relationships, and I have the proper foreign key columns, e.g. state_id in the state_links, counties, and cities tables.
I have also created scaffolds corresponding to each of the models.
One of the things I want is to have a view where the states are listed, and the user can click a hyperlink called "Show Links", and it will display all of the links associated with that state. I assumed I could modify the list view for state and use link_to, but I can't seem to figure out what information to feed it. I tried putting in something like: <%= link_to 'Show Links', :action => '../state_links/list', :id => state %> but that did not work. I get "no route found to match '/states/../state_links/li
st/6' with {:method=>:get}". Maybe this is the wrong way altogether, but I can't find any info on how to do something like this, which seems like a pretty important task to be able to do (show a new page with info from a related table).
I just started using Rails recently, and I am not a professional programmer, so please be easy on me and provide a thorough explanation that a non-professional like myself can understand.
Thanks!
Answer : In Ruby on Rails, how do I create links to other views that will display the correct results from a related table
You are Not linking to another View, but to another Controller..
So you could also try
<%= link_to 'Show Links', :controller=>:state_links, :action => :list, :id => state %>
Random Solutions
Virtual Memory
install server 2003 over win7
Cannot re-enable firewall with group policy
Sharepoint Survey: Clicked 'No' to 'Show user names while creating the survey! Is there a way to turn the feature back on to see the names again?
Virtual Data Recovery Error
Make wireless networking
run excel and run the enable auto refresh
Kernel panic not syncing VMWare Data Recovery 1.2
Blackberry Users can receive but not send
HOW TO DEACTIVATE ALL COMMANDS, TEXTBOXES AND DROPDOWN BOXES ONNA FORM?