Reputation: 627
%tbody
- @accounts.each do |account|
%tr
%td= link_to account['id'],show_path,{:id => account['id']}
%td= account['name']
%td= account['description']
%td= account['created']
The above is just a snippet from a haml file and in my controller i have the following:
def show
# If a system account already exists in session, it was found from a search with the account id
# Otherwise, this is a new search for a system account by the given id
@account = session[:account]
if @account.nil?
Rails.logger.debug { "Querying for the account with id: #{params[:id]}" }
response = query_account(CGI.escape(params[:id]))
@account = JSON.parse(response.body)
end
end
The route(show_path) is /system_accounts/:id
how do i pass the parameter id to the controller and link /system_accounts/23 if the id is 23 for eg: .
Upvotes: 3
Views: 6248
Reputation: 2213
This will link to the correct show page for the account:
= link_to account.id, account
You can always explicitly add any additional parameters to the path:
= link_to account.id, account_path(:id => account.id, :foo => "bar")
Upvotes: 12