ceth
ceth

Reputation: 45295

form_for for ordinary object

Can I use form_for orbinary object?

Controller:

class AgendaState
    attr_accessor :base_date

    def initialize(date)
        @base_date = date
    end
end

class TodayController < ApplicationController
    def agenda(base_date = Date.today)
        @agenda = AgendaState.new(base_date)

View:

<%= form_for(@agenda) do |f| %>
    <%= f.text_field :base_date %>
<% end %>

Error message:

undefined method `model_name' for AgendaState:Class

Upvotes: 1

Views: 929

Answers (1)

Pavel S
Pavel S

Reputation: 1543

The simplest way would be extend your class with ActiveModel

class AgendaState
 extend ActiveModel::Naming
 include ActiveModel::Conversion
 ...
end

Updated due to discussion in comments.

Upvotes: 5

Related Questions