Re: [Rails] Re: date_select -> params ok but nil

2014-11-21 Thread tom
hi

thx for all.

the reason why i asked is because some code i have used from the internet
was checking: params[:event][:from_date].empty?  , but mine was always nil
(as above). after assigning the params to a new model and checking then
fixed it for me.




On Thu, Nov 20, 2014 at 11:30 AM, Matt Jones  wrote:

>
>
> On Wednesday, 19 November 2014 17:40:50 UTC-5, der_tom wrote:
>>
>> hi,
>>
>> im kinda stuck...
>>
>> <%= form_for(@event) do |f| %>
>>   
>> <%= f.label :from_date %>
>> <%= date_select :event, :from_date %>
>>   
>>
>>
>> .
>>
>> def create
>> p params[:event].nil?
>> p params[:event][:name]
>> p params[:event][:from_date]
>>
>> if params[:event][:from_date].empty?
>>   params[:event][:from_date] = Date.today
>> end
>> ...
>> -->
>> Started POST "/events" for 127.0.0.1 at 2014-11-19 17:37:09 -0500
>> Processing by EventsController#create as HTML
>>   Parameters: {"utf8"=>"✓", "authenticity_token"=>"
>> JannWb1XCE12AKW4KlR56LAAmIOG1raHJh1ss4v0RBA=", "event"=>{"name"=>"",
>> "from_date(1i)"=>"2014", "from_date(2i)"=>"11", "from_date(3i)"=>"19",
>> "to_date(1i)"=>"2014", "to_date(2i)"=>"11", "to_date(3i)"=>"19"},
>> "commit"=>"Create"}
>>
>>
>  --> why are my event date attributes nil/blank?
>
> The date is not sent as a single attribute, but rather one per dropdown
> that date_select sends (thus from_date(1i) etc).
>
> When those attributes are assigned to your model, they are combined into a
> single object by ActiveRecord.
>
> You can either check for the subparts explicitly, or move the "default to
> today" behavior to the model instead.
>
> --Matt Jones
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/199cc138-1098-47ef-821d-5a5a5f297345%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMeM9gSL1QOHEq%3D90d%2BArA_bPOv-d02JE7PZhvKYnTJ72Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: date_select -> params ok but nil

2014-11-20 Thread Matt Jones


On Wednesday, 19 November 2014 17:40:50 UTC-5, der_tom wrote:
>
> hi,
>
> im kinda stuck...
>
> <%= form_for(@event) do |f| %>
>   
> <%= f.label :from_date %>
> <%= date_select :event, :from_date %>
>   
>
>
> .
>
> def create
> p params[:event].nil?
> p params[:event][:name]
> p params[:event][:from_date]
>
> if params[:event][:from_date].empty?
>   params[:event][:from_date] = Date.today
> end
> ...
> -->
> Started POST "/events" for 127.0.0.1 at 2014-11-19 17:37:09 -0500
> Processing by EventsController#create as HTML
>   Parameters: {"utf8"=>"✓", 
> "authenticity_token"=>"JannWb1XCE12AKW4KlR56LAAmIOG1raHJh1ss4v0RBA=", 
> "event"=>{"name"=>"", "from_date(1i)"=>"2014", "from_date(2i)"=>"11", 
> "from_date(3i)"=>"19", "to_date(1i)"=>"2014", "to_date(2i)"=>"11", 
> "to_date(3i)"=>"19"}, "commit"=>"Create"}
>
>
 --> why are my event date attributes nil/blank?

The date is not sent as a single attribute, but rather one per dropdown 
that date_select sends (thus from_date(1i) etc).

When those attributes are assigned to your model, they are combined into a 
single object by ActiveRecord.

You can either check for the subparts explicitly, or move the "default to 
today" behavior to the model instead.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/199cc138-1098-47ef-821d-5a5a5f297345%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: date_select -> params ok but nil

2014-11-20 Thread Mike
You're using the f.label and date_select helpers.  Try using f.date_select ?

On Wednesday, November 19, 2014 2:40:50 PM UTC-8, der_tom wrote:
>
> hi,
>
> im kinda stuck...
>
> <%= form_for(@event) do |f| %>
>   
> <%= f.label :from_date %>
> <%= date_select :event, :from_date %>
>   
>
>
> .
>
> def create
> p params[:event].nil?
> p params[:event][:name]
> p params[:event][:from_date]
>
> if params[:event][:from_date].empty?
>   params[:event][:from_date] = Date.today
> end
> ...
> -->
> Started POST "/events" for 127.0.0.1 at 2014-11-19 17:37:09 -0500
> Processing by EventsController#create as HTML
>   Parameters: {"utf8"=>"✓", 
> "authenticity_token"=>"JannWb1XCE12AKW4KlR56LAAmIOG1raHJh1ss4v0RBA=", 
> "event"=>{"name"=>"", "from_date(1i)"=>"2014", "from_date(2i)"=>"11", 
> "from_date(3i)"=>"19", "to_date(1i)"=>"2014", "to_date(2i)"=>"11", 
> "to_date(3i)"=>"19"}, "commit"=>"Create"}
> ..
> ..def instantiate_controller_and_action_names"
> "URL: http://localhost:3000/events";
> "Fullpath: /events"
> "events"
> "Action: create"
> "Controller: events"
> false
> ""
> nil
>
>
> --> why are my event date attributes nil/blank?
>
> tia
> tom
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/44886969-b7fd-417c-bffa-1aab854b9343%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.