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 8413667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:57:40+00:00 2026-06-10T00:57:40+00:00

The whole code is from this question: Nested form validations not working in rails

  • 0

The whole code is from this question: Nested form validations not working in rails app

The validation works, but now the problem is with error_message. It is simply not showing up.

I found out that it won’t work because of redirect_to in my controller:

class MessagesController < ApplicationController

  def create
    @trip = Trip.find(params[:trip_id])
    @message = @trip.messages.create(params[:message])     
  if @trip.messages.create
    MessageMailer.send_message(@message).deliver
    redirect_to thank_you_path        
  else    
    redirect_to trip_path(@trip)
  end
 end
end 

And I have to use render instead. But the question is how?

This message form is inside another models show page and if the message doesn’t pass validations, I want to see the error message in the same show page.

Can You help ?
Thanks!

Update:

rake routes

     messages GET    /messages(.:format)                         {:action=>"
 index", :controller=>"messages"}
             POST   /messages(.:format)                         {:action=>"
 create", :controller=>"messages"}
  new_message GET    /messages/new(.:format)                     {:action=>"
 new", :controller=>"messages"}
  edit_message GET    /messages/:id/edit(.:format)                {:action=>"
 edit", :controller=>"messages"}
     message GET    /messages/:id(.:format)                     {:action=>"
 show", :controller=>"messages"}
              PUT    /messages/:id(.:format)                     {:action=>"
 update", :controller=>"messages"}
              DELETE /messages/:id(.:format)                     {:action=>"
 destroy", :controller=>"messages"}
 trip_messages GET    /trips/:trip_id/messages(.:format)          {:action=>"
 index", :controller=>"messages"}
              POST   /trips/:trip_id/messages(.:format)          {:action=>"
 create", :controller=>"messages"}
 new_trip_message GET    /trips/:trip_id/messages/new(.:format)      {:action=>"
 new", :controller=>"messages"}
 edit_trip_message GET    /trips/:trip_id/messages/:id/edit(.:format) {:action=>"
 edit", :controller=>"messages"}
 trip_message GET    /trips/:trip_id/messages/:id(.:format)      {:action=>"
 show", :controller=>"messages"}
              PUT    /trips/:trip_id/messages/:id(.:format)      {:action=>"
 update", :controller=>"messages"}
              DELETE /trips/:trip_id/messages/:id(.:format)      {:action=>"
 destroy", :controller=>"messages"} 
  • 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-06-10T00:57:42+00:00Added an answer on June 10, 2026 at 12:57 am
    class MessagesController < ApplicationController
    
         def create
             @trip = Trip.find(params[:trip_id])
             @message = @trip.messages.build(params[:message])     
             if @message.save
                  MessageMailer.send_message(@message).deliver
                  redirect_to thank_you_path        
             else    
                  render "edit"
             end
         end
    end
    

    Then you should have a partial called _edit.html.erb within views/messages that contains your form and your code to render the errors.

    And your edit.html.erb can just be something like render "edit"


    Quick comment:

    you should change this:

    form_for([@trip, @trip.messages.build])
    

    to

    form_for([@trip, @message])
    

    And set @message (@message = @message.new) in the new action. That way, you can use the same form for the new and edit action.

    You could also think about using a gem like simple_form that makes creating forms a lot easier, and you would have errors displayed inline.

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

Sidebar

Related Questions

This is a follow-up question, but I'll include the code from before. I have
My question is sort of a follow on from this question below but I
I want to use this code (from my last question (thanks Adam)), bool AllDigitsIdentical(int
While implementing the code from this question on my project I realized there's 3
This question is asking virtually the same as this: Rails date format in form
in the book i'm learning from i came across this code snippit: while (i
i've a jquery (UI) App here where the whole JQuery Code gets a little
raw is a data.table and the following code works: raw[,r_responseTime] #Returns the whole column
Why is it that when I run this code in a loop, only whole
This is probably a simple question, but it's driving me crazy! I have 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.