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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:52:51+00:00 2026-05-30T18:52:51+00:00

In my header, users can add an item via a form. I want this

  • 0

In my header, users can add an “item” via a form. I want this option to be available on each page, so I have in my header :

<%= form_for(@item) do |f| %>

           <div>
              <div class="title"><%= f.label :name, "Name" %></div>
              <div class="champ"><%= f.text_field :name %></div>
          </div>

          <div>
              <%= f.submit "add this item" %>
          </div>
<% end %>

But it forces me to add this in each controller :

def action
    @item = Item.new
end

How can I avoid it ? Using Application controller ?

Thanks !

  • 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-30T18:52:52+00:00Added an answer on May 30, 2026 at 6:52 pm

    Define a method in application controller and use before_filter.

    class ApplicationController < ActionController::Base
      ..
      before_filter :initialize_item
    
      def initialize_item
        @item = Item.new
      end
    end
    

    initialize_item method will be executed on each request now.

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

Sidebar

Related Questions

I have a Custom Canvas(DesignerCanvas), user can add some controls to this canvas. Before
I'm using jQuery to dynamically add form elements to a web form. Users can
I have a WPF form that contains a DataGrid. This DataGrid is editable. One
I have all the boost header files in this repository and when I do
I've been using this tutorial to create a screen where a user can add
I have code which add item like below to xml file: <newWord> <Heb>rer</Heb> <Eng>twew</Eng>
I have a popup box that retrieves content data via AJAX and displays this
I have a file that users will purchase via paypal, clickbank and paydotcom. I
I have some ContextMenu With some menuItems. One of the menuItems is Add Item....
Are there any HTTP headers one can use to detect a mobile users number

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.