Sillico
Joined
Activity
Posted in Update a Rails record via API
Hi! I just finished watching Chris' API video and it was awesome! I am able to make GET requests to retrieve data in JSON format. However, I was wondering how could I update the record with a PATCH request? I don't think I'm still full grasping the idea of how the params work with the CURL command. I haven't played around with Rails in awhile and looking for some pointers. Thanks!
Posted in DRY Validations for Similar Models
In addition, here is the code I used for the solution Chris suggested, for anyone interested.
# /models/concerns/location_validations.rb
module LocationValidations
extend ActiveSupport::Concern
included do
validates :name, presence: true
validates :address, presence: true
validates :state, presence: true
validates :zipcode, presence: true
validates :country, presence: true
end
end
# models/restaurant.rb
class Restaurant < ApplicationRecord
has_many :branches
has_and_belongs_to_many :users
validates :phone, presence: true
validates :email, presence: true
include LocationValidations
end
# models/branch.rb
class Branch < ApplicationRecord
belongs_to :restaurant
validates :restaurant_id, presence: true
include LocationValidations
end
Posted in DRY Validations for Similar Models
Thanks to both of you for the solutions! That worked well.
Posted in DRY Validations for Similar Models
In my app I have restaurants which have a name, address, state, zipcode, country, and some other stuff. These restaurants have many locations, and each location belongs to a restaurant. The locations also hold a name, address, state, zipcode, and country. I was wondering if there is a clean way of writing validations in their model files without having to repeat myself in each model file? Can validations go into a function?
Thanks.
Posted in ElasticSearch 400 error.
I actually ended up watching the video and using parts of the video with what I had already built out to get the desired result. Great tutorial though!
Posted in ElasticSearch 400 error.
Hello!
I am pretty new to Rails and recently signed up to try to get some more exposure. I have been playing around with Elastic Search, but am having a hard time implementing some of the more advanced features. I watched the episode on GoRails, but when I try to boot up the server from the GoRails repo, I constantly get 400 errors. I tried searching my project directory for "fields" an found one result that I replace with stored_fields. Then I tried commenting out that function. However, nothing changes. What am I missing / doing wrong?
Searchkick::InvalidQueryError in QuestionsController#index
[400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":127}],"type":"parsing_exception","reason":"The field [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored","line":1,"col":127},"status":400}
def index
query = params[:q].presence || "*"
@questions = Question.search(query, suggest: true) # The highlighted line from the error page on rails server
end
# GET /questions/1