Topic: Log in user after view rendered

I have an apply view (index page) where the user can leave his
credentials if he applies from that views an account will be generated
an the user will be logged in. And an overview page will be shown
(create page)

But if he is already logged in and applies the sentence "we have send
your password to ... cannot be shown in my view.

So I have made the following:

      <% unless user_signed_in? %>
        <div class="row">
          <div class="three columns">
            <strong><%= t("apply.create.labels.password") %></strong>:
          </div>
          <div class="nine columns">
            <%= t("apply.create.labels.emailed_password_html", :link =>
mail_to(@user.personal_info.e_mail))%>
            <%= link_to(t("apply.create.labels.choose_password"),
user_profile_path) %>
          </div>
        </div>
        <!-- Try to Sign in User -->
        <% priv_sign_in %>
       <% end %>

This code is because. If the user applies the @user info is filled in
but he can only be logged in after this part of the view is generated.

In my applycontroller create I have the following to do priv_sign_in:

     # Helpers
      helper_method :priv_sign_in

      # Sign in User from View
      private
      def priv_sign_in
        sign_in(@user)
      end

Is there any better way to do is. So in an effort to make things more
clear.

When I enter the create view this has to be done:

If the user is logged in --> Hide part of view
If the user is not logged in --> Show part of view and try to log in


If it is not clear please ask some questions, thanks a lot! smile

Last edited by vwou (2013-04-12 08:19:40)