OK - I have a solution (not sure if it's the best one but it works)
- question.rb and answer.rb from above stay the same
To count the impressions of the answer show.html.erb page, I still use in the answer_controller, :
impressionist(@answer)
To count the impressions when I redirect from answer, I created a new def in the answer_controller:
def visit_external_site @answer= Answer.find(params[:answer_id]) impressionist(@answer) respond_to do |format| format.html {render :nothing => true, :status => 200} end end
(The part I'm not sure about is the format.html (I don't want to go anywhere but still....)
My routes.rb has this:
match '/:answer_id' => 'answers#visit_external_site', :as => 'visit_external_site'
- The questions\show.html.erb page has this now:
<% @question.answers.each do |answer| %>
<%= link_to url_for(:controller => :answers, :action => :visit_external_site, :answer_id => answer),
:class => 'answer_link', :remote => true,
:data => {outval:
answer.type_url, cuid: answer.id.to_s, refval:
user_question_path(@question.user, @question), txtval:
answer.img_url} do %>
<span class="small_image">
<%= image_tag(answer.img_url, :alt => 'go to answer', :class => 'img_answer') %>
</span>
<% end %>
<% end %>
- My jQuery is still the same as above
If anyone has a better way to doing this, do tell; I'm not sure if this way is "kosher"