Simon P

Joined

2,160 Experience
0 Lessons Completed
2 Questions Solved

Activity

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:

https://kernelgarden.wordpress.com/2014/02/26/dynamic-select-boxes-in-rails-4/

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

Hi

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?

Simon

Posted in Chartkick Graph Accumulate values

Hi

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?

Simon

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

https://github.com/basecamp/trix

https://github.com/thoughtbot/clearance

Posted in Using date_select only save the month into my DB

Hi

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?

Thanks

Simon

Posted in Date Picker for Rails App

Hi

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.

Thanks 

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: current_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

Hi

I have these tables:

Users which has many:
Farms which has many:
Stores

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.

Hi

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
@line_item.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 }
end
end

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

Thanks

Posted in Link_to error

Thanks

That Routing page is on my reading list already!!

Posted in Link_to error

Hi

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 www.oilersdaily.com/articles it links to www.oilersdaily.com/articles/about rather than www.oilersdaily.com/about

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!!

Thanks

Simon

Posted in Exception/error reporting from live.

They dont seem to do the free bugsnag plan on heroku - https://elements.heroku.com/addons/bugsnag

Might try Airbrake which does seem to have a free plan. - https://elements.heroku.com/addons/airbrake

Posted in Exception/error reporting from live.

@Jack

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.

Hi

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 honeybadger.io which looks about right but is this the best way and best option?

Thanks

Simon

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")

Posted in Link to a method in my model

Hi

I have a method called Search(search) in my model which is called from my controller. This works fine when I enter a search term in an input box in my view.

What I now want to do is create a link for a preset search term that pass the preset search term to the method.

Something like:

<%= link_to "Search Term", articles_search_path("Search Term") %>

How should this link look and what do I need in my controller to pass this to my model?

Thanks

Simon