Question

This is in the login action. I'm trying to adapt it to send back a return_url query param, and i'm failing with a simple render.

Prior:

  respond_to do |format|
    format.html {
      flash.now[:error] = error
      render
    }

Attempt 1:

  respond_to do |format|
    format.html {
      flash.now[:error] = error
      render return_url => "blah" 
    }

Attempt 2:

  respond_to do |format|
    format.html {
      flash.now[:error] = error
      render "login", local =>  {return_url => "blah"}
    }

No correct solution

OTHER TIPS

I passed params[:redirect_after_error] after an error and that solved it.

  respond_to do |format|
            format.html {
                flash.now[:error] = error
                 params[:redirect_after_error]  = params[:return_url]
              render
            }

From what I understand. You are trying to pass a return_url to the view. Right? So if you want that you can just create a instance variable that contains the value of the returning url For ex

@return_url = root_path() #or change it to url you want
#Then follow with the code you written
#You will see that you can use @return_url in the view without doing anything else.

If it doesn't answer your question. Could you be precise. I am not so sure I do understand your question correctly.

for this view should have one instance variable when its render, so if its fail you just render to root_path

ex:

@user = xxxx respond_to do |format|
if @user.save format.html { redirect_to @users, notice: 'user was successfully created.' }
else
format.html { render root_path, :alert: error }
end
end

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top