ruby on rails - How to define a link path -
i'm trying figure out how make app rails 4. keep getting stuck on basic things , don't seem able identify principles use going forward.
i have profile model , industry model. associations are:
profile:
has_and_belongs_to_many :industries, join_table: 'industries_profiles'
industry:
has_and_belongs_to_many :profiles, join_table: 'industries_profiles'
in profile show page, i'm trying link industry page:
<% @profile.industries.limit(5).each |industry| %> <%= link_to industry.sector.upcase, industry_path(@industry) %> <% end %>
i can't find works link.
i have tried following:
industry_path(@profile.industry) industry_path(@profile.industry_id) industry_path(industry) industry_path(profile.industry) industry_path(industry.id) industry_path(industry_id)
but of them guesses. don't know how ready api dock can't understand of content.
can see how link show page of other side of habtm association single record?
you can grab list of routes running rake routes | grep industry
in command line, give table prefix, action, , uri pattern. example:
industries /industries(.:format) industries#index post /industries(.:format) industries#create new_industry /industries/new(.:format) industries#new edit_industry /industries/:id/edit(.:format) industries#edit industry /industries/:id(.:format) industries#show patch /industries/:id(.:format) industries#update put /industries/:id(.:format) industries#update delete /industries/:id(.:format) industries#destroy
in case, should @ show
path. industry , append _path
end of whatever prefix above, comes out industry_path
. , since have declared variable industry
when defining loop, can use instead of instance variable.
short answer: industry_path(industry)
Comments
Post a Comment