oscarlopezalegre / homework3

0 stars 0 forks source link

Finished homework #1

Open oscarlopezalegre opened 8 years ago

oscarlopezalegre commented 8 years ago

@coderschoolreview

Find the homework 3 updated.

Please help me to review it shortly as I can't create more instances of heroku

Regards, Oscar

coderschoolreview commented 8 years ago

Thank you for your Ruby submission, oscarlopezalegre!

:x: Unfortunately there are some problems with your submission:

oscarlopezalegre commented 8 years ago

https://giphy.com/gifs/26tPprwWQrZXQXUXe

Find it here!

harley commented 8 years ago

Hi @oscarlopezalegre :+1: good job with the homework. The goal this week was to enhance a basic app with search, complex form, relationships between models and add tests on top of that.

I see that you attempted to use the nested_form gem. This gem isn't actively maintained so there may be rough edges. Did you have any trouble with it?

Overall, the functionalities are good! I just few a few suggestions:

# avoid this
<select name=<%= "type_id_"+type.id.to_s%>>
  <% 
    if type.max_quantity != nil and type.max_quantity < 11
        @max_quantity= type.max_quantity
    else
        @max_quantity = 11
    end
    @max_quantity.times do |i| %>
    <option> <%= i %> </option>
    </li>
  <% end %> 
</select>

Consider this instead:

# in app/models/event_type.rb
class EventType < ActiveRecord::Base
  MAX_QUANTITY_DEFAULT = 11

  # ...
  def max_quantity_or_default
    max_quality || MAX_QUANTITY_DEFAULT
  end
  # ...
end

# in app/views/tickets/new.html.erb
<select name=<%= "type_id_#{type.id}" %>
  <% @type.max_quantity_or_default.times do |qty| %>
    <option><%= qty %></option>
  <% end %>
</select>

It's even cleaner if you want to use Rails' helper:

<%= select_tag "type_id_#{type.id}", options_for_select((1..@type.max_quantity_or_default).to_a) %>

An alternative approach: you can also set a database default value for the max_quantity column to be 11!

def update
  @editing_event = Event.find(params[:id])
  if @editing_event.update_attributes(event_params)
    redirect_to myevents_path, flash: {success: "Message saved"}
  else
    redirect_to edit_event_path(@editing_event), flash: {warning: "Couldn't edit message")
  end
end
oscarlopezalegre commented 8 years ago

nesteed_form was working well for my app, My guess is that it was just a little of javascript library. It was important to have a single page for the users. In the future I might use it again.