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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:39:14+00:00 2026-06-11T04:39:14+00:00

I want to simply save the token parameter I receive from the JSON request,

  • 0

I want to simply save the token parameter I receive from the JSON request, but I simply cannot get to show if it is actually saved. I’ve observed that if you do a POST request with JSON parameters rails routes it to the create method. And I set my global variables attribute (in this case token), however when it redirects to the index.html.erb it gives me the error below

<h1>
  NoMethodError in
  Inits#show
</h1>

<p>
  Showing <i>/Users/alioral/Desktop/Rails/testApp2/app/views/inits/show.html.erb</i> where line <b>#3</b> raised:
  <pre><code>undefined method `token' for nil:NilClass</code></pre>
</p>

Here is my controller class;

class InitsController < ApplicationController
  def index
  end
  def show
  end
  def create
      @init=Init.new("token"=>params[:token])
      @init.save
      respond_to do |format|
        format.html { redirect_to @init }
        format.json { render json: @init }
      end
  end
end

And just in case here is the model I’ve generated (without using scaffold);

class Init < ActiveRecord::Base
  attr_accessible :token
end

Here is my show.html.erb file;

<h1>Hello, World</h1>
<b>The token is:</b>
<%= @init.token%>
  • 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-11T04:39:16+00:00Added an answer on June 11, 2026 at 4:39 am

    First, create does not redirect to index, it redirects to the new created @init path. Second, it looks like the show haml file contains a reference (in line 3) to @init.token, and since @init is nil you get this error.

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

Sidebar

Related Questions

I just want to simply save the selected index as integer but the code
I simply just want to count the clicks of a button and save the
I simply want to post an image and comment from my own site to
I simply want to fill-up cells in my spreadsheet from a VBA function. By
I simply want to show off a model in a table that is paginated
I simply want to change a variable of an object from another class. I
I simply want to generate a class with attributes that comes from a Database
I want my class to implement Save and Load functions which simply do a
I simply want to save in an email the true/false status of a check
This is my code and I want the save image button to simply 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.