ruby on rails - Unable to save or update ticket status -


I am making ticket booking applications for my sample project using Ruby on Ruby 4.1. There are three three models - There are many tickets and reservations in the event, tickets and booking events. There are many tickets in the ticket and they are related to the events. Booking is related to events and tickets.

Here is a ticket model:

  class tickets & lt; ActiveRecord :: base is_many: event has_many: booking before_create: check_start_date before_update: def self.check_start_date check_start_date if self.booking_start_date == Date.today self.update_attribute (: position => Open ') end end  < / Pre> 

Ticket Controller:

  Class Ticket Controller & lt; ApplicationController def index @event = Event.find (params [: event_id]) @tickets = @ event.tickets.all enddef show @event = Event.find (params [: event_id]) @ticket = @ event.tickets.find (Params [: id]) End DEF New @event = Event.find (params [: event_id]) @ tickets = tickets. Make New End DEE @Avent = Event.Find (PARAM [: Event_ID]) @ TK = @Avent @ Tickets.create (ticket_params) If @ ticket.save redirect_to [@event, @ticket] and then edit 'new' end-end def @event = Event.find (params [: event_id]) @ ticket = @ event. Tickets @ticket = @ event.tickets.find (params [: id]) Find the @ ticket.update (ticket_params) redirect_to (params [: id]) end def update @event = Event.find (params [: event_id]) [@event, @ticket] All other render 'edits' end end DEF deleted @event = Event.find (parameter [: event_id]) @ticket = @ event.tickets.find (parameter [: id]) @ ticket. Destroy redirect_to event_tickets_path Private End Def ticket_params (tickets) .permit (: ticket_name ,: booking_start_date, booking_end_date,: ticket_price, ticket_quantity ,: minimum_quantity ,: maximum_quantity ,: terms_conditions, more_information, status) end  part  F | & Gt%; & Lt;% = f.label: ticket_name% & gt; & Lt;% = f.text_field: ticket_name% & gt; & Lt;% = f.label: booking_start_date% & gt; & Lt;% = f.datetime_select: booking_start_date% & gt; & Lt;% = f.label: booking_end_date% & gt; & Lt;% = f.datetime_select: booking_and_data% & gt; & Lt;% = f.label: ticket_price% & gt; & Lt;% = f.text_field: ticket_price% & gt; & Lt;% = f.label: ticket_quantity% & gt; & Lt;% = f.text_field: ticket_quantity% & gt; & Lt;% = f.label: minimum_quantity% & gt; & Lt;% = f.text_field: minimum_quantity% & gt; & Lt;% = f.label: Maximum_Quality% & gt; & Lt;% = f.text_field: Maximum_Quality% & gt; & Lt;% = f.label: terms_contitions% & gt; & Lt;% = f.text_area: terms_conditions% & gt; & Lt;% = f.label: more_information%> & Lt;% = f.text_area: more_details%> & Lt;% = f.hidden_field: Status% & gt; & Lt;% = f.submit 'Create Ticket'% & gt;  

I use the hidden field for this: Partial position in the form and I am trying to update the value to open or close the model method by checking_start_data. However, I am not able to make or update tickets and I do not get any method errors in ticket controller, unscheduled method 'check_start_date'.

Where am I going wrong? Is it using hidden fields and a model method, so its status can be updated correctly?

  1. Do you need yourself in the method definition of check_start_date ? It seems that being used as an instance method compared to class instance method.
  2. In addition, do you want to update the attribute in the database in check_start_date or just set it? If you can call update_attribute inside check_start_data then there may be an infinite loop.

    def check_state_data if self.booking_start_date == dateToday self.status = 'Open' and end


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -