3

I need to add a new link 'map' in my Taxis listing page, I am using active-scaffold and Rails 3.2.1. My current page looks like the below. I need to show a link 'map' similar to edit/delete/show in each record. In my database I have fields name, lat, lng.

enter image description here

How can this be done. Please help.

Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88

1 Answers1

1

You have to add your link in the configure part in your controller.

I did it like this:

controller Admin::TaxisController < Admin::ApplicationController
  active_scaffold :taxi do |config|
    config.action_links << ActiveScaffold::DataStructures::ActionLink.new('map', :label => I18n.t('map'), :type => :member, :inline => false, :position => true)
  end
end

Of course you'll need to define this method in your controller as well.

def map
  # do something here
end

You can read more about it here.

KARASZI István
  • 30,900
  • 8
  • 101
  • 128
  • thanks a lot. one more thing I need is, I need to pass two arguments lat and lng. how can I pass this to the map function created. Currently the ID is being passed. I dont want to again run a query to fetch the lat and lng with that ID. I tried using , :parameters => {:lat => :lat, :lng => :lng} but it gets value as lat and lng not the value in database. – Amal Kumar S Mar 21 '12 at 11:18
  • config.action_links.add 'map', :label => 'View Current Location in Map', :page => true, :type => :member, :inline => false, :position => true, :html_options => {:target => '_blank'} – Amal Kumar S Apr 26 '12 at 15:48