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
What is the best way to get the current request URL in Rails? You should use request. original_url to get the current URL.
You should use request. original_url to get the current URL. For Rails 3: You can write "#{request.
You can write request. url instead of request. request_uri . This combines the protocol (usually http://) with the host, and request_uri to give you the full address.
request.referer gives you the previous URL or / if none. It is usually used to redirect the user back to the previous page (link)
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.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With