Hi, I have in my controller action book, but it looks ugly. How to refactor 
its right way?

 def book
>     if params[:date].present? && params[:room].present? && current_user
>       room = Room.find_by_id(params[:room])
>       date = DateTime.strptime(params[:date],"%d-%m-%Y-%H-%M")
>       unless date > Date.today+8.days || date.past?
>         unless 
> Book.user(current_user.id).room(room.id).period(room.period).first 
>           unless 
> Book.room(room.id).free(date,date+room.duration.minutes).first 
>             stop = (date+room.duration.minutes).strftime("%H:%M") == "00:00" 
> ? "23:59" : (date+room.duration.minutes).strftime("%H:%M")
>             unless  
> Book.room(room.id).cyclic.dayoftheweek(date.wday).onlytimefree(date.strftime("%H:%M"),stop).first
>                 redirect_to list_books_path(:room=>room)
>             else 
>               flash[:error] = "Obiekt #{room.name} is reserved each week"
>             end
>           else
>             flash[:error] = "Obiekt #{room.name} is not availible"
>           end
>         else
>           flash[:error] = "Obiekt #{room.name} can be reserved once on few 
> days"
>         end
>       else
>         flash[:error] = "wrong date"
>       end
>     else
>       flash[:error] = "no raservation parameters"
>     end
>   end
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/gbwpv_w55T8J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to