views:

26

answers:

2

In my app, I've got a little box that appears on every page, checking on the status of requests made by the user. If a request is accepted at any time, then the user should automatically be taken to a certain page. This is my code so far:

 <% offersMade.each do |w| %>
  <% if w.accepted == true %>
   <% redirect_to offer_path(:email => "[email protected]") %>
  <% end %>
 <% end %>

But I'm getting this error:

undefined method `redirect_to' for #<ActionView::Base:0x1042a9770>

Is it not possible to user redirect_to in a view? If not, is there something else I can use? Thanks for reading.

+1  A: 

redirect_to is not a method of ActionView. Its a method of ActionController. You can probably use Javascript window.location.href on page load or some other event to take your user to another page.

Suman Mukherjee
Thanks for your help, didn't know this.
ben
+1  A: 

redirect_to is a method of ActionController::Base Class so you can not use it in ActionView.

You can try following

<% if w.accepted == true  %>
  <script type="text/javascript">
    window.location.href="/logins/sign_up"  // put your correct path in a string here
  </script>
<% end %>

Edited for the email parameter

window.location.href="/logins/sign_up?email=<%= w.email %>"

Sorry i don't know if there is anything in ruby for that.

Salil
Thanks, this works great. Do you know if there is a way I can use a RoR variable in the url contruction? In my original code up the top, I have (:email => "[email protected]"), I'm not sure if I can do something similar from within javascript?
ben
check my edited answer.
Salil
Thanks so much, it works! I didn't think you could embed ruby in js but apparently you can. Thanks again!
ben