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 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 had to for some reason use a hidden field to persist an Id
I'm trying to use hidden fields in a form to pass along state selections
what parameters should i use to start a console app minimized or hidden? is
I've got a collection of hidden fields in my form. <ul id=user_roles> <li><hidden field
I need to use hidden variables in my JSP for session tracking. This is
In Firefox, I would use the page-worker component, that allows for arbitrary many hidden
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
I have a hidden field called Id on the page. I also have 2
Trying to do some jQuery validation (without the plugin - please no answers like
I want to create one insert function in php, which I will use to

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.