Leonel *-* wrote:
> Marnen Laibow-Koser wrote:
>> Why not just use collection_select?
> According to
> http://shiningthrough.co.uk/Select-helper-methods-in-Ruby-on-Rails "Use
> select when you require a basic drop-down selection box populated with
> data not sourced from a database"
You're right...I was thinking collection_select would work with a Hash,
but of course it won't.
>
>> And why not use Haml?
> I don't know what that is
But you know what Google is, right? :) Look it up!
>
>> Of course you did! The view has no access to model instance variables.
>> If you want to use @durations in the view, you'll need to set it in the
>> *controller*, not the model. Rails copies controller instance variables
>> to the view.
> I just tried it from the controller and gives me same error message.
>
> CONTROLLER
> @durations = {"30 minutes" => "30", "1 hour" => "60", "1 hour 30
> minutes" => "90", "2 hours" => "120"}
>
> ERROR
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.map
> Extracted source (around line #20):
>
> 17: </div>
> 18: <div class="field">
> 19: <%= f.label :duration %><br />
> 20: <%= f.select ("duration", @durations.map {|d| [d.id, d.name]},
> :prompt => "Select") %>
> 21: </div>
> 22: <div class="field">
> 23: <%= f.label :cost %><br />
Where in the controller are you setting the variable? Let's see the
entire controller method that you're using.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.