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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:21:58+00:00 2026-05-18T23:21:58+00:00

Use a hidden field will fix my issue… i got it.. Hi All, I

  • 0

Use a hidden field will fix my issue… i got it..

Hi All,

I am new to rails, trying to do some practice.
The app i am writing is trying to create a new “Post” See the view and controller below.

But it doesn`t work as what i expected…
the parameters pass to function “save”, there is no “post_at” field…

How can i fix it???
Thanks

INFO:   Parameters: {"authenticity_token"=>"Xc9VuvRL6GsUTaKyyNQxp8ovylEYwOMC+7hMcqdKizg=", "post"=>{"title"=>"First post", "content"=>"Write something"}, "commit"=>"save"}

View new_post.erb

<div class="post">
  <% form_for @new_post, :url => { :action => "save" } do |f| %>
    <p><%= f.error_messages %></p>
    <br/>
    <table>
      <tr>
        <td>Title</td>
        <td><%= f.text_field :title %></td>
      </tr>
      <tr>
        <td>Post at</td>
        <td><%= @new_post.post_at %></td>
      </tr>
      <tr>
        <td>Message</td>
        <td><%= f.text_area :content, :cols => 100, :rows => 10 %></td>
      </tr>
    </table>
    <br/>
    <%= f.submit 'save'%>
  <% end %>
</div>

Post Controler

class PostController < ApplicationController
  def index
    @all_posts = Post.find(:all)

    render :action => "post"
  end

  def new
    @new_post = Post.new
    @new_post.post_at = Time.now

    render :action => "new_post"
  end

  def save
    @new_post = params[:post]
    Post.create(@new_post)

    redirect_to "/post"
  end
end

Data Model:

class Post
  include DataMapper::Resource
  storage_names[:default] = "Post"

  property :id,      Serial
  timestamps :at

  property :title,        String,        :required => true, :length => 500
  property :content,      Text,          :required => true, :lazy => false
  property :post_at,      DateTime
end
  • 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-18T23:21:58+00:00Added an answer on May 18, 2026 at 11:21 pm

    First off, your development will be a lot easier if you follow the REST principles.

    Your controller should instead of save implement the create and update methods.

    
    def index
      @posts = Post.all
    end
    
    def new
      @post = Post.new
    end
    
    def create
      @post = Post.create(params[:post])
      redirect_to @post
    end
    
    def show
      @post = Post.get(params[:id])
    end
    
    def edit
      @post = Post.get(params[:id])
    end
    
    def update
      @post = Post.get(params[:id])
      @post.update_attributes(params[:post])
      redirect_to @post
    end
    
    def destroy
      @post = Post.get(params[:id])
      @post.destroy
      redirect_to posts_path
    end
    

    This is a complete REST controller which has the views index.html.erb, new.html.erb, edit.html.erb, show.html.erb all in app/views/posts.

    Sidenote: If you’re new to Rails, it might be a good idea to learn how to use it with ActiveRecord before trying on DataMapper. That way you can use rails generate scaffold to get a full example of a way to do all this.

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

Sidebar

Related Questions

I will use model.id when referencing the id for the table in the database,
I am trying to use Authorize.net's SIM payment gateway process and am using the
I would like to use the same view for editing a blog post and
The Problem I have a page with a form on. It has a hidden
My question is that with example. I have to show all categories of books
i have a dropdownlist control in asp.net which resides in a user control .The
I would like to store data temporarily on clientside. What is the best way
I have a form where I'm using Jquery to submit the form to create
Apologies I can't post any code at this time cos I'm away from my

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.