5

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

AndraD
  • 2,830
  • 6
  • 38
  • 48

3 Answers3

6

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.

nzifnab
  • 15,876
  • 3
  • 50
  • 65
1

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?

Stanislav Mekhonoshin
  • 4,276
  • 2
  • 20
  • 25
0

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.

Community
  • 1
  • 1
jdl
  • 17,702
  • 4
  • 51
  • 54
  • I had a look at this posting a bit earlier. When trying request.fullpath within the form, I get "/feedback/new". Maybe the path needs to be defined somewhere outside the form? – AndraD Sep 20 '12 at 03:06
  • What are you expecting to see here? Do you have an example? – jdl Sep 20 '12 at 03:13
  • Sure, so let's assume I am on the http://localhost:3000/projects page when I want to leave a feedback note. I would like to have "/projects" saved to the database when submitting the feedback form, but instead "/feedback/new" would be saved. – AndraD Sep 20 '12 at 03:18