ruby-on-railsrubypostgresql-9.4form-for

How can I check what happens when I submit a form in RoR?


My lists_controller.rb provides @list and @lists from the duplicate method

  def duplicate
    @lists = List.includes(:list_fields, :user, :list_parts)
    @list = List.new
    respond_to do |format|
      format.html
    end
  end

And I have got a form in my duplicate.html.erb file.

<%= form_for( @list, :html => { :class => "formtastic normal", :id => "generator_form" }) do |f| -%>
        <fieldset>
          <ol>
            <li>
              <%= label_tag :list_source, "Available lists" %>
              <%= select "list", "original_id", @lists.sort{|a,b| a.title <=> b.title}.collect{|p| [p.title[0,50]+"...", p.id] }, { :include_blank => "Please select a list" } %>
            </li>
          </ol>
        </fieldset>
        <p><%= f.submit "Duplicate" -%></p>
<% end -%>

The select helper gives me a drop down menu from which I can select a list. When I click submit, a new list is created (from an existing one) and saved in my database but I don't really know what happens behind the scene when I submit (click "Duplicate"). How can I check that ?


Solution

  • Just use Rails logger. In development environment it prints out information in terminal when server is running

    Also it writes logs in file. By default destination is log/<environment>.log

    So you can use tail command. For example, to read output in real time in production

    tail -f log/production.log
    

    Also you can specify logging level and setup log message format

    And you can manually call logger in your code like this

    Rails.logger.info 'your message'
    

    In logs you will see requested action and controllers, parameters from your form, SQL-queries, what was rendered or where redirected etc.

    Please read more in official guide