Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:22:25+00:00 2026-05-22T14:22:25+00:00

In my rails application, I’ve got a partial view with an entry form on

  • 0

In my rails application, I’ve got a partial view with an entry form on it. The form gets included on multiple pages across my app. The form in the partial posts to a RidesController to save with a create method like this:

RidesController.rb

def create
  @ride = current_user.rides.build(params[:ride])
  if @ride.save
    flash[:success] = "Ride created!"
    redirect_to root_path
  else
    @rides = current_user.rides.paginate(:page => params[:page])
    render 'pages/home'   # <---- WHAT GOES HERE?
  end
end

I’ve commented the line where my question is. When we have an error, I need to present the same view that the user is presently on. But because this controller is being invoked from a partial instead of a full view, I don’t know how to tell what context it’s coming from.

Right now if there’s an error on /rides/new, the user ends up redirected to the homepage which also has the form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:22:26+00:00Added an answer on May 22, 2026 at 2:22 pm

    One way you could do this is pass the template path in with the form.

    Add this to each main view that includes the form partial (e.g. pages/home, rides/new, etc):

    <% @current_page_template = __FILE__ %>
    

    In your form partial:

    <%= form_for ... do |f| %>
      <%= hidden_field_tag 'current_page_template',
          @current_page_template.sub(File.join(Rails.root, 'app', 'views'), '') %>
    

    In your controller:

    def create
      ...
      if @ride.save
        ...
      else
        ...
        render params[:current_page_template]
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a rails application where users have to log in. Therefore in order
In a rails application, in which situation would you use a partial and when
I'm building a rails application and have come across what seems to be strange
I have rails application that connects to multiple databases. I wrote custom rake task
I have multiple rails application running at a server. Each one at one port
I have a rails application and i keep getting this error /srv/projects/app/controllers/application_controller.rb:174: invalid multibyte
My Rails application has a number of tasks which are offloaded into background processes,
My Rails application makes use of Time.zone so that each user can set their
I have a rails application where each user has a separate database. (taking Joel
I have a rails application which is still showing the cachebusting numeric string at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.