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
How do I register Exchange 2010 with Windows Server Backup on Windows Server 2008 R2
website
IIS host header and DNS
In a excel document is there a way to view two sheets at the same time (i.e. side by side).
Save Machine and User Accounts in Windows 2008 SBS
importing another ACT DB
SBS 2008 Small Business Server Internet Activity
WMIC Get Hard drive serial number
Using SpamAssassin's Command-line Spam Score Test
couple of things missing from Exchange 2010?