Alan Kirk

Joined

750 Experience
6 Lessons Completed
0 Questions Solved

Activity

Hey Chris, I'm having a play around with this, as it's pretty amazing what it's doing. I have a question about implementing the ActionCable delivery. I can't get the notification channel to deliver to the recipient. I've tried with the default setting, and then I've tried setting the channel. When I check the logs I can see "[ActionCable] Broadcasting to :: {params}". I can't work out where the is coming from. Shouldn't it be the ID of the recipent? When I broadcast through the channel manually from the rails console using "ActionCable.server.broadcast ":, {params}", I get a notification as expected. Not sure if I've missed something, or having something configured wrongly?

Posted in Dynamic Nested Forms with Stimulus JS Discussion

I've been playing around with Stimulus over the last couple of evenings, trying to implement drag and drop sorting. Everything is working as expected when swapping elements on the page around. I seem to be fighting a battle, however, getting an AJAX post to send data from my stimulus controller to my rails controller. No parameters are being passed in the AJAX post.

In my stimulus contrller I have the following code

var data =  {
      data: {
        name: "test"
      }
    };

    Rails.ajax({
      dataType: 'json',
      type: 'POST',
      url: '/projects/test',
      data: { data },
      success: function(data) {
        console.log(data);
      },
      error: function (response) {
        console.log(response);
      }
    })

When the code is triggered I'm not seeing anything parameters passed over in the log. All I see is

Started POST "/projects/test" for ::1 at 2019-03-06 22:30:42 +0000
Processing by ProjectsController#test as JSON
<ActionController::Parameters {"controller"=>"projects", "action"=>"test"} permitted: false>

Looking in the Chrome Inspector, it looks like the data is being sent as [object Object]. If I add a query string to the URL, the parameters show as expected. I've tried all sorts of combinations of using JSON.stringify and JSON.parse, but no joy.

If I change the type to "GET" I get the following in my log

Started GET "/projects/test?[object%20Object]" for ::1 at 2019-03-06 22:47:40 +0000
Processing by ProjectsController#show as JSON
  Parameters: {"object Object"=>nil, "id"=>"test"}

It feels like i've exhausted all options, with no luck. I'm probably missing someting obvious. If anyone has an pointers or suggestions, they'd be most welcome. Think in the meantime I'll go back to Cocoon, just to get it working and then refine it later

Posted in Dynamic Nested Forms with Stimulus JS Discussion

Great episode, I've been using Cocoon in past projects to add a "content section block" to a page, which then has different types of content associated to it (ie textarea, text with image, image gallery, etc.), so that it can then be reordered if needed.

I'd like to use more Stimulus moving forward, so interested in trying this technique out.

One part that I could never quite suss out, was when adding a content section block with a file auto uploader, such as jQuery File Upload (for multiple images/or documents) I couldn't upload anything until the content section block was saved to the database via a page save.

I guess with Stimulus, a new nested field could be saved to the database within the Stimulus controller, when it's added to the form? Then there would be an ID to use for any files to upload against.

Saying that, with a move away from jQuery, would Stimulus be able to deal with file uploads in a simular way to jQuery File Upload or is it best to leave that sort of thing to ActiveStorage?

I know what you mean! In my day job, it's always the first thing I ask others before going further with any investigations, and I fell into the same trap!

Ok, getting somewhere now. It's working in the main app.

I've got an "all day" checkbox, which I was trying to use .sort_by{|event| [event.all_day ? 0 : 1, event.start_time]} to filter to the top, before sorting the other events by date. I'll see if I can figure out how to do that. That and passing in an end time for the event. Turns out that adding end_at to

schedule(start_time).occurrences(end_date).map do |date|
        Event.new(id: id, title: title, start_at: date, color: news_events_category.color, recurring: recurring, is_recurring: true)
end

stops all the recurring events from showing. I'm sure there's a reason for that. Hopefully watching the screencast again will fill in some blanks.

Thanks again for your help (and putting up with some basic queries)

So, turns out I was using an old version of the gem. Updating it made a multi-day event show on each of the days in the test app I set up.

Updating the gem on the app I need it to work, gets it to work too when using

<% sorted_events.fetch(day, []).each do |event| %>

to loop through the events. However, as my calendar is also showing recurring events (using the ice_cube), the code is checking for recurring events, and re-ordering based on showing all day events first, it's using revised code instead

<% @events.select{ |m| m.start_time.to_date == day}.sort_by{|event| [event.all_day ? 0 : 1, event.start_time]}.each do |event| %>

I've pasted in a previous comment about, what the events_controller and Event model are doing to create @events. I can see that multi-day bit isn't working due to the check for m.start_time.to_date == day.

Is it possible to override the events used in sorted_events to use those from @events?

Due to time differences and it being way after midnight, I've just done this.

Set up a new app with a simple_calender setup, following the guide on the gem github page, using the multi-day scaffold example.

On my Meeting index view i've used

<%= month_calendar events: @meetings, attribute: :start_time, end_attribute: :end_time do |date, meetings| %>
  <%= date %>
  <% meetings.each do |meeting| %>
    <div>
      <%= meeting.name %>
      <%= meeting.inspect %>
    </div>
  <% end %>
<% end %>

and it's still only showing the event on the start day only.

No worries.

Busy is good, victim of your own success : ) All the more reason for appreciating you taking the time.

Putting that in (and disabling my overriding _week_calender layout) I'm seeing the same results, with the multi-day event only showing on the start day.

As I'm not doing solid rails work all the time, my understanding of how things work just isn't strong enough for me to know how to dip deeper into what's going on and figure it out. Trying to turn that around, by doing more rails work and figure out a bit more how to decipher how it all works, so all help is invaluable!

Hi Chris,

Appreciate you're a busy man. Wanted to check in with you, as to whether you had any thoughts / ideas as to whether I'm not seeing the multi-day events due to something I'd configured wrongly, or it's something else?

Many thanks again,

Alan

It's quite possible that something's not wired up properly. I've picked the work up from someone else, and having to re-code parts of it.

One thing that I think might be causing problems, is that it's also using IceCube for recurring events.

My events_controller has

def weekly_planner
    @all_events = Event.not_hidden
    @events = @all_events.order(:all_day).flat_map{ |e| e.calendar_events(params.fetch(:start_date, Time.zone.now).to_date) }
  end

In the model I've got

def calendar_events(start)
    if recurring.empty?
     Event.new(id: id, title: title, start_at: start_at, end_at: end_at, color: news_events_category.color, recurring: false, all_day: all_day)
    else
      schedule(start_time).occurrences(end_time).map do |date|
        Event.new(id: id, title: title, start_at: date, end_at: end_at, color: news_events_category.color, recurring: recurring)
      end
    end
  end

I had some problems with something else in the calender_events method, due to the new Event object created here.

My calender is also showing all day events, so I'm having to group events by all day events, then list out other events on that day ordered by start time.

The weekly_calender partial is doing the grouping and sorting, using

<% @events.select{ |m| m.start_time.to_date == day}.sort_by{|event| [event.all_day ? 0 : 1, event.start_time]}.each do |event| %>

Hopefully that helps to build a bit of a picture for you. Let me know if you need anything more

Hey Chris,

Thanks for replying.

I'm got end_attribute set up in

<%= week_calendar events: @events, attribute: :start_at, end_attribute: :end_at do |date| %>

What's the best way to share the code? snippets or the full code?

Hi there,

Not sure if i've missed something, but i'm not able to get multi-day events to show over the date range using SimpleCalendar.

From what I've read on the Gem homepage, I've passed in the end date attribute option to the calender_helper, but when viewing the results I only see the event showing on the first day, but it doesn't show on the following days.

I've followed some of the videos, which seems to use a "starts_at" value, to compare against day to be displayed, which I presume has something to do with it. I can't see anything obvious about using an "ends_at" value too to check and see if the day falls inside that range.

Has anyone else encountered this, or have I missed something obvious?

Many thanks in advance,

Alan

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.