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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:06:17+00:00 2026-05-27T10:06:17+00:00

def create @addpost = Post.new params[:data] if @addpost.save flash[:notice] = Post has been saved

  • 0
def create
    @addpost = Post.new params[:data]
    if @addpost.save
        flash[:notice] = "Post has been saved successfully."
        redirect_to posts_path
    else
        flash[:notice] = "Post can not be saved, please enter information."
    end
end

If the post is not saved then it redirects to http://0.0.0.0:3000/posts , but i need to stay on the page, with text input fields so that user can input data.

post model

class Post < ActiveRecord::Base

    has_many :comments
    validates :title, :presence => true
    validates :content, :presence => true
    validates :category_id, :presence => true
    validates :tags, :presence => true
end

new method

def new
    @arr_select = { 1=>"One",2=>"Two" ,3=>"Three" }
    @categories_select = Category.all.collect {|c| [ c.category_name, c.id ] }
end

new.html.erb

<h3>Add post</h3>

<%= form_tag :controller=>'posts', :action=>'create' do %>
    <%= label :q, :Title %>
    <%= text_field :data, :title, :class => :addtextsize %><br/>
    <%= label :q, :Content %>
    <%= text_area  :data, :content, :rows=>10 , :class => :addtextarea %><br/>
    <%= label :q, :Category %>
    <%= select :data, :category_id, @categories_select %><br/>
    <%= label :q, :Tags %>
    <%= text_field :data, :tags, :class => :addtextsize %><br/>
    <%= label :q, :Submit %>
    <%= submit_tag "Add Post" %>
<% end %>

What should i do ?

  • 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-27T10:06:18+00:00Added an answer on May 27, 2026 at 10:06 am

    flash.now with render is what you’re looking for.

    flash.now[:notice] = "Post can not be saved, please enter information."
    render :new
    

    Also instead of

    flash[:notice] = "Post has been saved successfully."
    redirect_to posts_path
    

    you can just write

    redirect_to posts_path, :notice => "Post has been saved successfully."
    

    and it will do the same thing. It works only with redirect_to though, not with render!

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

Sidebar

Related Questions

def create item = current_administrator.items.build(params[:category1]) item.created_at = Time.now item.save! redirect_to root_path end The code
Consider this code of my Controller: def create change_some_db_values buyer = Buyer.new(params[:buyer]) if buyer.save
I have this code : def create login(params[:email], params[:password]) if current_user flash[:notice] = Welcome
Here is the create in rfq controller: def create if has_create_right? @rfq = Rfq.new(params[:rfq],
I have the following code: def create @user = User.new(params[:user]) simp_ = User.new(params[:user]) if
i have 2 controllers methods create and show def create @message2 = Message.new(params[:message]) if
Using Rails 3.1.0 def create @practice = Practice.new(params[:practice]) respond_to do |format| if (current_user.practices <<
class ItemController < ApplicationController def create item = current_user.items.build(params[:presentstem]) item.created_at = Time.now item.save! redirect_to
I have the following methods in my controller: def create @user = User.new(params[:user]) if
I want to make simple authentication like # SessionController require 'session.rb' def create Session.new(params[:email],

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.