title: Ruby on Rails: Define a variable for a certain timestamp, which can be edited by the app user
body: <p>my goal is to define a variable (@deadline) for a certain timestamp, which can be edited by the app user. I had the approach to solve that problem by creating a show view, which offers a form to the user.</p>
  
  <pre><code>&lt;%= link_to "Anmeldefrist setzen", show_deadline_path(@deadline), :method =&gt; 'get' %&gt;
  </code></pre>
  
  <p>that show view is accessible and works how I want it, the struggle starts, when I push the button to submit the timestamp.</p>
  
  <pre><code>&lt;% if logged_in? and current_user.admin? %&gt;
    &lt;% provide(:title, "Anmeldefrist setzen") %&gt;
    &lt;div class="small_jumbotron jumbotron"&gt;
      &lt;h1&gt; Anmeldefrist setzen &lt;/h1&gt;
        &lt;div class="row"&gt;
        &lt;div class="Links"&gt;
          &lt;%= form_tag(:controller =&gt; "preferences", :action  =&gt; "update_deadline", :method =&gt; :put) do %&gt;
            &lt;%= label @deadline, "Anmeldefrist" %&gt;
            &lt;br&gt;
            &lt;%= datetime_select @deadline, value: @deadline %&gt;
            &lt;br&gt;
            &lt;%= submit_tag "Speichern", class: "btn btn-primary" %&gt;
            &lt;br&gt;
          &lt;% end %&gt;
          &lt;h2&gt; &lt;%= link_to image_tag('back2.png'), matching_path %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The routes file doesn't accept the method "put" from the form. I also tried to do it with "patch" before. I always get a routing error. </p>
  
  <pre><code>No route matches [POST] "/update_deadline"
  </code></pre>
  
  <p>I will add log file, routes.rb and controller now, thanks to everyone, who tries to help! You can also criticize my approach and propose another one, but I would appreaciate detailed instructions.</p>
  
  <p>Thanks! Kind regards 
  Moritz</p>
  
  <p>Log:
          Started GET "/show_deadline" for 127.0.0.1 at 2018-03-07 16:45:48 +0100
          Processing by PreferencesController#show_deadline as HTML
            Rendering preferences/show_deadline.html.erb within layouts/application
            [1m[36mUser Load (0.2ms)[0m  [1m[34mSELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
            Rendered preferences/show_deadline.html.erb within layouts/application (20.8ms)
            Rendered layouts/_rails_default.html.erb (131.7ms)
            Rendered layouts/_shim.html.erb (0.8ms)
            Rendered layouts/_header.html.erb (4.6ms)
            Rendered layouts/_footer.html.erb (0.8ms)
          Completed 200 OK in 183ms (Views: 180.2ms | ActiveRecord: 0.2ms)</p>
  
  <pre><code>    Started POST "/update_deadline?method=put" for 127.0.0.1 at 2018-03-07 16:45:54 +0100
  
      ActionController::RoutingError (No route matches [POST] "/update_deadline"):
  
      actionpack (5.1.2) lib/action_dispatch/middleware/debug_exceptions.rb:63:in `call'
      web-console (3.5.1) lib/web_console/middleware.rb:135:in `call_app'
      web-console (3.5.1) lib/web_console/middleware.rb:28:in `block in call'
      web-console (3.5.1) lib/web_console/middleware.rb:18:in `catch'
      web-console (3.5.1) lib/web_console/middleware.rb:18:in `call'
      actionpack (5.1.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
      railties (5.1.2) lib/rails/rack/logger.rb:36:in `call_app'
      railties (5.1.2) lib/rails/rack/logger.rb:24:in `block in call'
      activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
      activesupport (5.1.2) lib/active_support/tagged_logging.rb:26:in `tagged'
      activesupport (5.1.2) lib/active_support/tagged_logging.rb:69:in `tagged'
      railties (5.1.2) lib/rails/rack/logger.rb:24:in `call'
      sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
      actionpack (5.1.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
      actionpack (5.1.2) lib/action_dispatch/middleware/request_id.rb:25:in `call'
      rack (2.0.4) lib/rack/method_override.rb:22:in `call'
      rack (2.0.4) lib/rack/runtime.rb:22:in `call'
      activesupport (5.1.2) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
      actionpack (5.1.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
      actionpack (5.1.2) lib/action_dispatch/middleware/static.rb:125:in `call'
      rack (2.0.4) lib/rack/sendfile.rb:111:in `call'
      railties (5.1.2) lib/rails/engine.rb:522:in `call'
      puma (3.9.1) lib/puma/configuration.rb:224:in `call'
      puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
      puma (3.9.1) lib/puma/server.rb:435:in `process_client'
      puma (3.9.1) lib/puma/server.rb:299:in `block in run'
      puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>Rails.application.routes.draw do
  
    resources :preferences
    resources :institutes
    resources :users
    resources :admin, to: 'users#admin'
  
    get 'password_resets/new'
    get 'password_resets/edit'
  
    root 'static_pages#home'
    get '/home', to: 'static_pages#home'
    get '/help', to: 'static_pages#help'
    get '/about', to: 'static_pages#about'
    get '/contact', to: 'static_pages#contact'
    get '/matching', to: 'static_pages#matching'
    get '/cockpit', to: 'static_pages#cockpit'
  
    get '/signup', to: 'users#new'
    post '/signup',  to: 'users#create'
  
    get '/performance_show', to: 'users#performance_show'
    get '/performance_update', to: 'users#performance_update'
  
    post 'preferences/create_all', :to =&gt; 'preferences#create_all'
  
    get '/login', to: 'sessions#new'
    post '/login', to: 'sessions#create'
    delete '/logout', to: 'sessions#destroy'
  
    resources :account_activations, only: [:edit]
    resources :password_resets,     only: [:new, :create, :edit, :update]
  
    get '/show_deadline', :to =&gt; 'preferences#show_deadline'
    patch '/update_deadline', :to =&gt; 'preferences#update_deadline'
  
    post 'preferences/delete_matching', :to =&gt; 'preferences#delete_matching'
    post 'preferences/read_and_show_ofv', :to =&gt; 'preferences#read_and_show_ofv'
    post 'preferences/read_matching', :to =&gt; 'preferences#read_matching'
    post 'preferences/optimize_matching', :to =&gt; 'preferences#optimize_matching'
  
    post 'preferences/optimize', to: 'preferences#optimize'
  
  end
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>  def show_deadline
      if @deadline.nil?
        @deadline = 0
      end
    end
  
    def update_deadline
      if @deadline.update_attributes
        flash[:success] = "Die Deadline wurde aktualisiert."
        redirect_to matching_path
      else
        flash[:error] = "Die Präferenz konnte nicht aktualisiert werden."
        redirect_to preferences_path
      end
    end
  </code></pre>