Skip to main content

Posts

Showing posts with the label Ruby on Rails Test Upwork

Ruby on Rails Test Upwork Answers 2019

1. For the String class, what’s the difference between «#slice» and «#slice!»? Answers: • None, «#slice» is just an alias for «#slice!». • There is no «#slice!» method in Ruby on Rails. • «#slice» returns a new object, «#slice!» destructively updates — mutates — the object’s value. 2. How to pass variable “projects” into ERB template from controller? Note: There may be more than one right answer. Answers: • @projects = Project.all • render locals: { projects: Project.all } • render projects: Project.all • render :index, projects: Project.all 3. How to permit nester attributes in Rails controllers for such model? class User has_one :profile accepts_nested_attributes_for :profile end Answers: • params.require(:user).permit(:email, profile: [:id, :_destroy]) • params.require(:user).permit(:email, profile: {:id, :_destroy}) • params.require(:user).permit(:email, profile_attributes: [:id, :_destroy]) • params.require(:user).permit(:email, profile_attributes: {:id, :_destro...