Simon P


2,170 Experience
0 Lessons Completed
2 Questions Solved


Posted in How to access a webpage and get its content

Have a look at the Nokogiri gem

Posted in Need to do cascading select lists in Rails 5

I worked it out following:

Just in case anyone comes through here looking for the same.

Will try and redo it in Stimulus when I get chance.

Posted in Need to do cascading select lists in Rails 5


Struggling with this one....

Quite a few articles around but most quite old, really would like to use Stimulus but I cant find any pointers.

Have a locations Select.

One a selection is made I want a AJAX style population of the rooms Select where each location has_many rooms.

Any ideas or guidance please?


Posted in Chartkick Graph Accumulate values


Using Rails, Chartkick and Groupdate I have a graph which shows values.

In the view:

<%= line_chart @ContractsForChart.group_by_month(:contract_date).sum(:units), xtitle: "Months", ytitle: "Units Sold" %>

In the controller:

@ContractsForChart = Contract.joins(:store)

I would like the values (the units) to accumulate, how could I do this please?


Posted in Need a Best CMS for Rails App Landing page

You could use something like clearance to control access to the editor and then something like Twix to perform the actual editing

Posted in Using date_select only save the month into my DB


I have this code which shows a dropdownlist on the page showing just the month in words, e.g. December.

<%= form.label :movement_month %>
      <%= form.date_select :movement_month, order: [:month] %>

I would like to save just the month into my database but instead it is saving {1=>2018, 3=>1, 2=>6} into the database, obviously when I need to read that vakue I can pick out the month but is there anyway I can make it save just the month?



Posted in Charts with Chartkick and Groupdate Discussion

Working through this, I think:

//= require Chart bundle 

Needs to be:

//= require Chart.bundle 

Posted in Date Picker for Rails App


What would be the recommended data picker for my Rails app?

Seem to be  a lot of options but many haven't been maintained in a while.


Posted in Need some help with an Active Record Query

Thank you!

Posted in Need some help with an Active Record Query

Thanks for everyones help.

I have added the "through" action.

My code looks like:

@stores = Farm.joins(:stores).where(stores: {marketing_year: view_year}).where(farms: {user_id:})
But I get error:

undefined method `farm_id' for #<Farm:0x007f8d8352e708>
Did you mean?  farm_name

So I guess the query isn't returning the data I am hoping for when it tried to bind in the view.

Apologies for beginner level questions!

Posted in Need some help with an Active Record Query

Reading this back I should probably explain some more detail.

Users have multiple farms

Farms have multiple stores

I need a query that returns all stores for any farm being to current_user

Posted in Need some help with an Active Record Query


I have these tables:

Users which has many:
Farms which has many:

I want to return stores that belong to a specific user_id.

Got this far but Rails is giving me an error.

Thanks in advance for any assistance.

Posted in Jquery destroy seems to fire twice.


I get the confirm msgbox "are you sure" twice and have to OK it twice:

<%= button_to 'Remove', line_item, method: :delete, data: {confirm: 'Are you sure?'} %>

In controller:

def destroy
respond_to do |format|
format.html { redirect_to store_index_url(@line_item.cart_id), notice: 'The item was removed from your cart' }
format.json { head :no_content }

How can I stop this? I have tried a few things that I found on Google without success!!


Posted in Link_to error


That Routing page is on my reading list already!!

Posted in Link_to error


I have my header in a partial which then appears on every page through the application template.

In the header I have an About link:

<%= link_to "About", 'about' %>

This works fine in most of the site.

But when I am in it links to rather than

about.html.erb is in the folder static_pages and my routes.rb has :

get 'about', to: 'static_pages#about'

Any guidance appreciated, a schoolboy error I am sure!!



Posted in Exception/error reporting from live.

They dont seem to do the free bugsnag plan on heroku -

Might try Airbrake which does seem to have a free plan. -

Posted in Exception/error reporting from live.


Looking at bugsnag and it looks very nice.

I dont think I can use the free plan on Heroku though?

Posted in Exception/error reporting from live.

Thanks guys.

Posted in Exception/error reporting from live.


When my app crashes in live it would be nice to get emailed the stack trace/error info.

Does anything exist to do this?

I found which looks about right but is this the best way and best option?



Posted in Link to a method in my model

Fresh start to a new days and nailed this myself:

<%= link_to "Search Term", articles_path(search: "Search Term")

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.