0

I'm doing an application for booking movie. For each movie have a "book" button, normally it just direct to another page handled by a controller. But is there any way to do like this? if user not login before, show a popup to redirect to login page, else direct to booking controller?

Current in my movie controller is:

<td><%= button_to "Book", {:controller => "booking",:action=>"new", :movie_session_id => movie.id}, :method => :post %></td>

is it possible if I check condition in this page or I have to check in BookingController?

Phu Tang
  • 415
  • 6
  • 16
  • I think **link_to** would be appropriate in this case. You can check **current_user** is present or not and accordingly you can use which link_to should take user to BookingController's new action or take user to thelogin page. – dp7 Mar 26 '16 at 07:25

2 Answers2

2

You can try the following-

<td>
<% if current_user %>

    <%= link_to "Book", {:controller => "booking",:action=>"new", :movie_session_id => movie.id}, :method => :post %>
<% else %>
  <%= link_to "Book", login_path %>
<% end %>
</td>
dp7
  • 6,651
  • 1
  • 18
  • 37
0

link_to_if(current_user.blank?, "Book", login_path) do

link_to "Book", {:controller => "booking",:action=>"new", :movie_session_id => movie.id, :method => :post}

end

if the user is logged in than it redirect to login page else it will redirect to booking new form

Vishal
  • 7,113
  • 6
  • 31
  • 61