Search code examples
ruby-on-railsslim-lang

Proper controller action link syntax using slim


Rails 3.2

In my view, I have:

= form_for CustomerInfo.new  do |f|
  .form-horizontal-column.customer-info
    .form-group
      = f.label :first
      = f.text_field :first, maxlength: 50
    .form-group
      = f.label :last
      = f.text_field :last, maxlength: 50
    .actions = link_to "Save", :controller => :CustomerInfo, :action => :create

This causes a 500 error with no additional error information.

If I replace the last line with:

    .actions = f.submit 'Save'

Then the form renders fine.

Any idea why the original syntax is not working?


Solution

  • You are likely getting an error because the route you specified in the link_to does not exist.

    When you use the :controller option, you need to specify it in snake case and plural (to match the plurality of the actual controller name).

    So if your controller is named CustomerInfosController, you write that as controller: :customer_infos