Every time you call render or redirect instance disappear from memory, here
is how it work: a resquest comes in, the router figures out the controller
and action to use and you load/save data, then present it by rendering the
view, after this point, the server will wipe out the memory used for that
request, so, when you loaded the index, and rendered the index, it was over
for the live of that instance, then, the user clicks new, and a new
instance is created but with empty attributes, then is used to create the
form and passes to the view, after that is wiped from memory. now the form
that is created has the data in html and the user insert more data, when
the user click submit the server will take those parameters (params) and
used it inside Appoinment.new(params) to create a new instance with the
attributes that come in the post request of the form, at this point
@appointments does not exists, if you try to do anything with its value is
nil.

About the end, its could be that a 'do' is missing a 'else' is incorrect,
or a missed an 'end' somewhere.

On Wed, Jun 29, 2016 at 4:39 PM, Ruth Stephenson <[email protected]>
wrote:

> Than you so much for your reply and your help! I'm still a little
> confused however as I'm still getting an error:
>
> syntax error, unexpected end-of-input, expecting keyword_end
>
> I don't know why it's complaining about end keywords. As far as I can
> tell they are ok.
>
>
> I don't understand what you mean when you say:
> "# @appointments has not been loaded, is nil, you will get an error
> here
>     # you can add a before_action filter and load it there
>     @appointments.find(params[:date, :timeslot]) # dont load this here
> since is not always needed"
>
> Isn't the @appointments.find(params[:date, :timeslot]) not instanciated
> in the index method above?
>
> Do you mean to put a before_action filter in the appointments
> controller?
>
>
> appointments controller:
>
> def create
>     @appointment = Appointment.new(appointment_params)
>
>       respond_to do |format|
>       unless @appointments.isValid?
>
>
>
>         if @appointment.save
>           format.html { redirect_to @appointment, notice: 'Appointment
> was successfully created.' }
>           format.json { render :show, status: :created, location:
> @appointment }
>         elsif
>           format.html { render :new }
>           format.json { render json: @appointment.errors, status:
> :unprocessable_entity }
>         else
>           redirect_to root_path
>         end
>     end
>   end
>
>
> appointments Model:
>
> class Appointment < ActiveRecord::Base
>
>         def isValid?
>         date.present? && timeslot.present?
>     end
> end
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/690b189b71c3f828d7959f10659683fb%40ruby-forum.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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CANkJ5gnsEa5viczgiurJYQOQgWmmKNzv%2BE%3DiJ%3DNgC2SHUbJsNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to