Question

I am working with David Francisco's rails feedback plugin. The plugin works fine, except for one thing - I would need the feedback form to submit to the database the url for the page where the feedback form was used. Does anyone know how to do this?

The view that would need to send the current url, in addition to the currently sent information:

<h4>Feedback</h4>
<p>Please leave us feedback, it's really appreciated.</p>

<%= form_for @feedback, :as => :feedback, :url => feedback_index_path, :html => { :id => "feedback_form" } do |f| -%>
  <%= f.hidden_field 'user_id', :value => current_user.id %>
  <% unless @error_message.blank? %>
  <p class="error">
    <%=h @error_message %>
  </p>
  <% end %>
  <p>
    <%= f.label 'subject' %>
    <%= f.select 'subject', ['Problem', 'Suggestion', 'Question', 'Other'] %>
  </p>
  <p>
    <%= f.label 'comment' %><br />
    <%= f.text_area 'comment', :rows => 10, :cols => 30 %>
  </p>
  <p><%= f.submit 'Send' %></p>
<% end -%>

Currently, feedback_index_path is always '/feedback', the url for the form.

Thank you, Alexandra

Was it helpful?

Solution

You can use request.referer in your controller to get the path of the page that called your action. request.referer returns a full url but you can parse it with the URI module:

URI(request.referer).path

I see some people have suggested request.fullpath but this is actually the path of the action that's processing the request (in your case /feedbacks/new) and not the path where the form was submitted from.

OTHER TIPS

feedback_index_path is a routes helper method that will always return the same thing. In your case /feedback.

Look here for info on accessing the current URL in both Rails 2 and 3.

If request.fullpath doesn't work incorrectly, you can make a quick hack, storing page url in data-attributes of page, and on submit get current url by jQuery from that attributes. But it is a hack, just to make it working.

BTW how do you render feedback form?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top