views:

27

answers:

1

I have the following problem. I have a form which takes input for a "Chart" object. But after processing the form, i wish to display one of the values, and it adds the key of this value.

Class model

class Chart 

attr_accessor :title, :series

  def initialize(title = nil, series = [])
      @title, @series = title, series
  end
end 

View of form:

<% form_for :chart , :url => { :action => "show" } do |f| %>

<p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
</p>...
<% end %>

Chart controller, show method:

def show

    @chart = Chart.new(params[:chart])
end

View of show:

<h2><%=h @chart.title %></h2>

Which displays: "title"input_forms_title""

for example: writing in the input form: Economy, prints in the show view: "titleEconomy"

Any ideas?

A: 

Hello, I have just figured it out. The problem was in the constructor or initialize method. By changing the initialize method to:

def initialize( options = {} )
    @title = options[:title]
    @series = []
end

It now accepts all params perfectly!

jalagrange