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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:26:47+00:00 2026-06-17T03:26:47+00:00

I have made a resource. resources :dashboards I have a partial file which contains

  • 0

I have made a resource.

resources :dashboards

I have a partial file which contains a form and I want to use this partial (as the form elements won’t change) to update and create. So here is what I have:

Controller

class DashboardsController < ApplicationController
 def new     
    @dashboard = Dashboard.new
  end
end

View

/dashboards/new.html.erb

<%= render :partial => "form", :locals => { :dashboard => @dashboard } %>

Partial Form

/dashboards/_form.html.erb

<%= form_for(@dashboard) do |form| %>
.....
<% end %>

Ruby Guide

The Ruby Guide states:

The Article model is directly available to users of the application, so — following the best practices for developing with Rails — you should declare it a resource. When dealing with RESTful resources, calls to form_for can get significantly easier if you rely on record identification. In short, you can just pass the model instance and have Rails figure out model name and the rest. For example:

## Creating a new article
# long-style:
form_for(@article, :url => articles_path)
# same thing, short-style (record identification gets used):
form_for(@article)

## Editing an existing article
# long-style:
form_for(@article, :url => article_path(@article), :html => { :method => "put" })
# short-style:
form_for(@article)

Result

I thought I have followed the Rails Guide correctly. Because I made @dashboard a resource. I could just pass it into the form and have it handle the action, method and the rest. Instead I’m getting this:

<form accept-charset="UTF-8" action="/dashboards" class="new_dashboard" id="new_dashboard_" method="post">

According to the docs. Shouldn’t the action of my form now be “/dashboards/new” because we are on the new action? And should it be passing an extra field declaring the method to be put when I use the same code in the /edit action??

My result is always the same no matter what. The form never changes.

What am I doing wrong?

EDIT

Here is my router info from rake routes

GET    /dashboards(.:format)          dashboards#index
POST   /dashboards(.:format)          dashboards#create
GET    /dashboards/new(.:format)      dashboards#new
GET    /dashboards/:id/edit(.:format) dashboards#edit
GET    /dashboards/:id(.:format)      dashboards#show
PUT    /dashboards/:id(.:format)      dashboards#update
DELETE /dashboards/:id(.:format)      dashboards#destroy
  • 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-17T03:26:48+00:00Added an answer on June 17, 2026 at 3:26 am

    You are correct that you should be able to “pass @dashboard into the form and have it handle the action, method and the rest.” The issue here is what new is in the context of RESTful actions.

    When you declare a set of resources with resources :dashboards, you are creating a set of routes which map requests to controller actions:

    GET     /dashboards             index
    GET     /dashboards/new         new
    POST    /dashboards             create
    GET     /dashboards/:id         show
    GET     /dashboards/:id/edit    edit
    PUT     /dashboards/:id         update
    DELETE  /dashboards/:id         destroy
    

    You can check this if you run rake routes.

    The issue here is that the new action is defined as a GET request to the path /dashboards/new, i.e. this is the route for the form itself. The URL in the action attribute of the actual form is something else: this is where the form will post the data to with a POST request, which on the server (rails) side will map to the create controller action.

    When you use the form helper with form_for(dashboard), a form is created with a route corresponding to what dashboard is: if it is a new record (i.e. it does not yet exist in the database), then the form action will be create (and point to /dashboards), whereas if it already exists it will point to the actual URL for the record (e.g. /dashboards/123). This is what makes the form helpers so useful.

    So, to sum up, /dashboards is the correct URL, not for the new action but for the create action, which the form helper uses because dashboard is a new record. new is the route to the page where the form resides, i.e. /dashboards/new.

    Hope that makes sense.

    p.s. as a side note, you shouldn’t be accessing @dashboard in the partial if you are passing it in as a local (:locals => { :dashboard => @dashboard }). Just use dashboard.

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

Sidebar

Related Questions

I have made a simple username/password dialog to which I want to apply a
I have made a simple form with one textField and command, I want to
I have made a build system for my web application that's rewriting all resource
I have made an application for IPad in objective C. In this I am
I have made an iphone application like flip cards in which values of cards
I have a nested resource: resources :users do resources :cust_uploads end After uploads are
I have some icon resources as DrawingImage s that is made up of many
I want to display the contents of one resource within another. I think this
I have a static class in which one property defines a resource manager. for
Here is my usecase: I have web resources and for each resource a set

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.