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

  • Home
  • SEARCH
  • 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 6674987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:47:52+00:00 2026-05-26T03:47:52+00:00

I have a Pages model with field ‘customURL’. I can do page#show at ‘/:customurl’.

  • 0

I have a Pages model with field ‘customURL’. I can do page#show at ‘/:customurl’. but because i’ve defined page show that way in routes, my create action now does a redirect on success to the wrong route. What should I change to most cleanly fix the redirect properly to point to ‘/:customurl’ on save?

controller:

def create
  @page = Page.new(params[:page])

  respond_to do |format|
    if @page.save
      format.html { redirect_to page_url, notice: 'Page was successfully created.' }
      format.json { render json: @page, status: :created, location: @page }
    else
      format.html { render action: "new" }
      format.json { render json: @page.errors, status: :unprocessable_entity }
    end
  end
end

routes:

resources :pages
...
get "/:customURL" => "pages#show"

Thanks!

  • 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-26T03:47:53+00:00Added an answer on May 26, 2026 at 3:47 am

    In routes.rb, you can add magic helpers.

    get "/:customURL" => "pages#show", :as => :custom
    

    Then in your controller

    format.html { redirect_to custom_url(@page. customURL), notice: ... }
    

    Now, “/:customURL” will need to be last in your routes.rb, routes are greedy, the first to match will get it. So if you have something like “/bob” and you have a controller listening at “/bob”, the controller will get it before the pages controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF page that displays a RichFaces Treeview, from a TreeNodeImpl model
I have a single model in CakePHP that has multiple forms on different pages
Using Mongoid 2.4.5 on Rails 3.2.1 I have a Model Book that has_many :pages
i want to ask a question that how can i increment a model field
I have a page based on a model object, and I want to have
I have a page that opens a modal dialog. After the operations done on
I have a page that displays a table in two different modes. In each
I have 2 models: Pages ------------ Page User S500 John Gimp John WoW John
I have two models pages and author, here is the code of model pages:
I have a Model with data that I want to use to populate a

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.