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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:27:31+00:00 2026-05-19T16:27:31+00:00

I’m using Rails 2.3.8 I’m having an issue with the actions that get rendered

  • 0

I’m using Rails 2.3.8

I’m having an issue with the actions that get rendered after an error in a form.

So I have a posts controller and the regular related actions, index, new, create, edit, update, and show.

Here are the actions with forms in PostsController:

def new
  @post = Post.new
  # other setup
end

def create
  if request.post?
    @post= Post.new(params[:post])
    # other setup for save
    if @post.save
      flash[:notice] = 'Post was successfully created.'
      redirect_to campaign_path(@post, :redirect => "create")
    else
      render :action => 'new'
    end
  end 
end

def edit
  @post = Post.find(params[:id])
  # other setup
end


def update
  # setup for save
  if @campaign.update_attributes(params[:post])
    flash[:notice] = 'Your post was successfully updated.'
    redirect_to :action=> "index"
  else
    render :action => "edit"
  end
end

And here are the forms in the views

new.html.erb:

<% form_for(@post, :html => {:multipart => true}) do |f| %>
  <%= f.error_messages %>
  # Form fields and stuff
  <%= f.submit "Create New Post" %>
<% end %>

edit.html.erb:

<% form_for(@post, :html => {:multipart => true}) do |f| %>
  <%= f.error_messages %>
  # Form fields and stuff
  <%= f.submit "Update This Post" %>
<% end %>

My problem is: If I’m on the new page and I make some error (e.g. leave a field empty), the views that render submit to the wrong place. So if I start out on new and submit unsuccessfully a bunch of times, it takes me successively through new, then create, then edit, then update actions. So the behavior is:

Start out creating a post:

Action: new
URI: /posts/new
View rendered: new
Successful submit goes to: show
Unsuccessful submit goes to: create

After first unsuccessful submit:

Action: create
URI: /posts bad?
View rendered: new
Successful submit goes to: index (this means the form is submitting to the update action, bad)
Unsuccessful submit goes to: edit bad

After second unsuccessful submit:

Action: edit bad, I shouldn’t be able to get here from new!
URI: /posts/[id]
View rendered: edit bad, I shouldn’t be able to get here from new!
Successful submit goes to: index through update
Unsuccessful submit goes to: update

After third and subsequent unsuccessful submits:

Action: update bad, I shouldn’t be able to get here from new!
URI: /posts/[id]
View rendered: edit bad, I shouldn’t be able to get here from new!
Successful submit goes to: index
Unsuccessful submit goes to: update

I’d appreciate if anyone can point me to what I’m doing wrong. If you need any additional information just ask.

Thanks so much!

  • 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-19T16:27:32+00:00Added an answer on May 19, 2026 at 4:27 pm

    The problem is probably the code that you are using to create your post (# setup for save). You are probably setting @post.id which is causing your new form to submit to update instead of create. The form_for helper checks if a record is new or not, if it is new then it submits to create, if it already exists it submits to update.

    Note: You also don’t need to check request.post? on your create action. The create action should always be a post request.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.