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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:14+00:00 2026-06-14T14:49:14+00:00

def create @emppede = Emppede.new(params[:emppede]) respond_to do |format| if @emppede.save format.html { redirect_to :action

  • 0
def create
    @emppede = Emppede.new(params[:emppede])

    respond_to do |format|
      if @emppede.save
        format.html { redirect_to :action => :index, :id => @emppede.ad }
        format.json { render json: @emppede, status: :created, location: @emppede }
      else

        format.html { render action: "new", :id => @emppede.ad } *(....error)*
        format.json { render json: @emppede.errors, status: :unprocessable_entity }
      end
    end
  end

I have to pass id in new method. Here if the data is save properly then it goes to index method. But if not then it should go to new but with the params id. How could i pass the params through render action? Here i want to do but param id is not passed to new method. I highlighted that part by error.
If i do

 format.html { redirect_to :action => :new, :id => @emppede.ad }

Then it do not give errors message…

I have to pass user id to the new method so that i can pass it through the form and save.

<div id="employm" style="display:none">


    <%= f.text_field :ad, :value=> @id%>

            </div>

But when the form get error it render to new but here i have to send the
id which is in @emppede.ad.
How can i do this?
Since in order to enter in new method there should be id passed

redirect_to :action => :new, :id => @id
  • 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-14T14:49:15+00:00Added an answer on June 14, 2026 at 2:49 pm

    All instance variables you define in your controller action are present in the view.
    So if you define @id = 11 in your controller you can access it in the view using <%= @id %>.

    If you want to do this over a redirect you can simply can access the parameters inside the view (or use them first in the controller and then use the instance method above.

    Your posted code is a bit cryptic, but render will not enter the new method but only render the new.html.erb in the current context. So if you declared @id in your create action and render new you’ll have it present.

    When redirecting to :action you’ll have to pass the @id as a parameter.

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

Sidebar

Related Questions

I have the following controller action: def create @board = Board.new(params[:board]) respond_to do |format|
Using Rails 3.1.0 def create @practice = Practice.new(params[:practice]) respond_to do |format| if (current_user.practices <<
Is there a difference between def create @user = User.new(params[:user]) if @user.save redirect_to root_url,
Here is my unaltered controller: def create @user = User.new(params[:user]) respond_to do |format| if
What i have: (Action in Controller) def create @test = Test.new(params[:test]) @test.save devicefiles =
I have the following controller code: def create @admin = Admin.new(params[:admin]) respond_to do |format|
In my users_controller.rb I have: def create @user = User.new(params[:user]) respond_to do |format| if
def create item = current_administrator.items.build(params[:category1]) item.created_at = Time.now item.save! redirect_to root_path end The code
In my create action, method new acts like create. def create @page = Page.new(params[:page].merge(:user_id
Consider this code of my Controller: def create change_some_db_values buyer = Buyer.new(params[:buyer]) if buyer.save

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.