Search code examples
ruby-on-railsactiverecordhamlkoala

Rails 4.0.1 Creating Database Record from link_to


I am trying to create a new record when a user pushes a button. The page seems to be refreshing but no records are being created

%tbody
- page_list.each do |page|
  %tr
    %td.text-center=image_tag "https://graph.facebook.com/#{page['id']}/picture?width=40&height=40"
    %td= link_to page['name'], "http://www.facebook.com/#{page['id']}"
    %td= page['category']
    %td
      %span.webicon.facebook
    %td
      =link_to 'Import Page', pages_path(:page => { name: page['name'], page_id: page['page_id'] }, :controller => :pages), :class => 'button default tiny'
      =link_to 'View Page', "http://www.facebook.com/#{page['id']}", class: 'button default tiny'

Solution

  • Change your link_to to:

    = link_to 'Import Page', pages_path(:page => { name: page['name'], page_id: page['page_id'] }), :class => 'button default tiny', :method => :post
    

    And it's going to work. Links default to use GETbut what you need is a POST here.