How to use company_name on the url instead of company_id

12 views
Skip to first unread message

Shabbir Ahmed

unread,
Jan 14, 2016, 7:02:23 AM1/14/16
to rubyonra...@googlegroups.com
Hi all, How to use company_name on the url instead of company_id.

This is my routes:

get 'company/:company_id' => 'company#company', as: :company

This is my controller:

@company_view = Company.find(params[:company_id])

This is view:

<%=link_to company.company_name, company_path(:company_id => company_id)
%>

Thanks

--
Posted via http://www.ruby-forum.com/.

nanaya

unread,
Jan 14, 2016, 7:06:02 AM1/14/16
to rubyonra...@googlegroups.com


On Thu, Jan 14, 2016, at 21:01, Shabbir Ahmed wrote:
> Hi all, How to use company_name on the url instead of company_id.
>

This should help.

http://api.rubyonrails.org/classes/ActiveRecord/Integration/ClassMethods.html#method-i-to_param
Reply all
Reply to author
Forward
0 new messages