Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering a view after logging in which contains imputed information before being logged in
    primarykey
    data
    text
    <p>I have a blog in my website where only authenticated users can post. If an existing user that is not yet authenticated is typing a comment when he hits "create" he wil be redirected to the login view to authenticate and then redirected to the articles view. I would like to improve the functionality of my blog by rendering the view where the user was creating the comment so that he doesn't have to type in his comment again.</p> <p>I am rather new to programming and to ruby so I am not sure how to approach this problem. Any suggestions are welcomed. Thank you in advance.</p> <p>My website can be found at <a href="https://github.com/MariusLucianPop/mariuslp-" rel="nofollow">https://github.com/MariusLucianPop/mariuslp-</a> </p> <p>Bellow are what I think are the important parts of the code. Let me know if you would like me to update anything. </p> <p><strong>comments_controller.rb</strong></p> <pre><code>before_filter :confirm_logged_in, :only =&gt; [:create] def create article_id = params[:comment].delete(:article_id) @comment = Comment.new(params[:comment]) @comment.article_id = article_id @comment.posted_by = session[:username] @article = Article.find(article_id) if @comment.save redirect_to article_path(@article) else render "articles/show" end end protected def confirm_logged_in unless session[:user_id] flash[:notice]="Please login before posting a comment." redirect_to login_path return false else return true end end </code></pre> <p><strong>visitors_controller.rb</strong></p> <pre><code>def login #atempting to log in authenticated_user = Visitor.authenticate(params[:username],params[:password]) if authenticated_user session[:user_id]=authenticated_user.id session[:username]=authenticated_user.username flash[:notice] = "You are now logged in." redirect_to articles_path end else if !params[:username].blank? # only rendering the notice if the user tried to login at least once flash[:notice] = "Invalid username/password combination. Please try again" end render "login" end end </code></pre> <p><strong>routes.rb</strong></p> <pre><code> root :to =&gt; "static_pages#index" get "static_pages/work_in_progress" get "categories/new" match "work" =&gt; "static_pages#work_in_progress" match "login" =&gt; "visitors#login" # not rest match "logout" =&gt;"visitors#logout" # not rest resources :articles do resources :comments end resources :tags, :taggings, :visitors, :categories match 'contact' =&gt; 'contact#new', :as =&gt; 'contact', :via =&gt; :get match 'contact' =&gt; 'contact#create', :as =&gt; 'contact', :via =&gt; :post </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload