Does online map infinty code support satellite navigation Posted: 13 Dec 2016 07:52 AM PST I'm currently using google maps free asset on unity and feel i have reached the end of my abilities with this program. I'm thinking about buying the google maps online map infinity code asset but i'd like to know if it can actually do what i need as its not very clear on the description. Pretty much i want to set up my own app that has satellite navigation... i.e if i'm in London and type Liverpool it will give me a planned route and follow me until i reach the destination... does online maps asset support these features... if not is there a program or asset i can use to do this. thank you. |
Postgresql connection refused error on Windows 10 Posted: 13 Dec 2016 07:50 AM PST I've been trying to use postgres with Ruby on Rails for the past week. The first time I downloaded postgres, there was a "Password not supplied" issue that was resolved by uninstalling and redownloading. Now, I have tried uninstalling and reinstalling twice, because I am getting a connection refused error that looks like this, ... "could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?" ... I've looked over many online resources, including stackoverflow and none have seemed to help. This is what my pg_hba.conf file looks like .... # TYPE DATABASE USER ADDRESS METHOD # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. #host replication postgres 127.0.0.1/32 md5 #host replication postgres ::1/128 md5 ... and here is my postgresql.conf file ... listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '' # comma-separated list of directories # (change requires restart) #unix_socket_group = '' # (change requires restart) #unix_socket_permissions = 0777 # begin with 0 to use octal notation Most of the suggestions were based on these two files which were already configured correctly according to the answers to the posts. I also tried disabling the firewall and restarting postgres. Does anyone have any suggestions for me? Thanks! |
How to merge hash of hash without replacing first hash Posted: 13 Dec 2016 08:11 AM PST Consider two hashes: h1 = {a: 1, b: 2, d: {g: 7, h: 6}} h2 = {a: 1, b: 2, d: {m: 4, n: 5}} I was trying merge both hashes as: h1.merge(h2) Result: {:a=>1, :b=>2, :d=>{:m=>4, :n=>5}} Can someone guide me to get a hash like: {:a=>1, :b=>2, :d=>{:m=>4, :n=>5, :g=>7, :h=>6}} I had tried using deep_merge as suggested by some of other answers which didn't work. |
Rails and modules Posted: 13 Dec 2016 07:53 AM PST I want to create a module for query objects. I created a file: app/queries/invoices/edit.rb with this class: module Queries module Invoices class Edit end end end However, I can't initialize it: 2.3.3 :001 > Queries::Invoices::Edit.new NameError: uninitialized constant Queries When I omit the Queries module, everything works: module Invoices class Edit end end 2.3.3 :005 > Invoices::Edit.new => #<Invoices::Edit:0x007fc729e15558> Why is that? |
Rails user settings and permissions Posted: 13 Dec 2016 07:34 AM PST I am using Rails 4 and would like to create a simple web application. So currently I just have this models: Post and User . The user should of course be able to change his settings like his firstname, lastname, email, etc. but there is more. He should be able to set some other settings based on permissions. I have found some modules, that might do the job: https://github.com/plataformatec/devise - flexible authentication solution https://github.com/CanCanCommunity/cancancan - authorization library This two combined will do the job I guess. But now there is more. Let's for example say I decide that a user can change his permissions of his posts (e.g. Who can leave a comment on his posts). I just want to know is there a good user settings library for rails which combines with devise and cancancan perfectly? Or is it just okay, if I always update my user model with an additional attribute? Because I want to split permission and general settings from another. Furthermore I want that a user can even set some settings to his subscriptions and so on. |
Validate Rails login Posted: 13 Dec 2016 08:15 AM PST I have a SessionsController in my Rails app like so: class SessionsController < ApplicationController def new if @current_user.present? redirect_to dashboard_path else @title = 'Log in' render :layout => 'other' end end def create user = User.find_by_email(params[:session][:email]) if user && user.authenticate(params[:session][:password]) session[:user_id] = user.id redirect_to params[:redirect_url].present? ? view_context.b64_decode(params[:redirect_url]) : '/admin/dashboard' else redirect_to login_path(params[:redirect_url].present? ? {:redirect_url => params[:redirect_url]} : {}), :alert => 'Invalid credentials' end end end So basically two methods, one to show the login form, and one to handle the post request to check the credentials. On success, create a session and redirect, or on error, redirect back the login form with an alert. However I'd like to use the Rails validations to give more information about what the issue was, e.g. email or password blank, incorrect email or password combination, locked out user, etc. I can't create a model because I don't have a DB table called Sessions, so I wouldn't want to use that... How can I use the Rails validations to validate a form like this? The only way I could think of getting the level of detail I was after was to create a method like so and then call that from the controller. def check_login if params[:session][:email].blank? && params[:session][:password].present? redirect('Email address missing') elsif params[:session][:email].present? && params[:session][:password].blank? redirect('Password missing') elsif params[:session][:email].blank? && params[:session][:password].blank? redirect('Email address and password missing') else user = User.where(email: params[:session][:email]).first if user.present? if user.authenticate(params[:session][:password]) session[:user_id] = user.id redirect_to params[:redirect_url].present? ? view_context.b64_decode(params[:redirect_url]) : '/admin/dashboard' else redirect('Incorrect email/password combo') end else redirect('Unknown user') end end end def redirect(alert) redirect_to login_path(params[:redirect_url].present? ? {:redirect_url => params[:redirect_url]} : {}), :alert => alert end and then my controller method is just: def create @session = check_login end But is their a cleaner way to do it using the Rails validators? |
RSpec - testing instance variables within a controller Posted: 13 Dec 2016 07:37 AM PST I have a new action which creates a circle and assigns the current parent as its administrator: def new return redirect_to(root_path) unless parent @circle = Circle.new(administrator: parent) end I'm trying to test that the administrator ID is properly set, and have written out my test as such: context 'with a parent signed in' do before do sign_in parent allow(controller).to receive(:circle).and_return(circle) allow(Circle).to receive(:new).and_return(circle) end it 'builds a new circle with the current parent as administrator' do get :new expect(@circle.administrator).to equal(parent) end end This obviously throws an error as @circle is nil . How can I access the new object that hasn't yet been saved from my controller tests? I'm guessing it is some variety of allow / let but as I say all my searches have yielded nothing so far. |
rspec undefined method `id' for nil:NilClass Posted: 13 Dec 2016 08:21 AM PST require 'rails_helper' feature "comment" do given(:current_user) do create(:user) end given(:undertaking) do create(:undertaking) end background do login_as(current_user) end scenario "can create comment" do #below two because undertaking = user_id:2 & asking_id:1 create(:user) create(:asking) p undertaking p Asking.find(1) p User.find(2) p User.find(1) p Undertaking.all visit undertaking_path(undertaking) expect(current_path).to eq undertaking_path(1) within("form#undertake-form-test") do fill_in "content" , with: "heyheyhey" end click_button 'Send' expect(page).to have_content 'heyheyhey' end end This is spec/features/comment_spec.rb. and this below is result command rspec. #<Undertaking id: 1, title: "MyString", content: "MyText", result: false, user_id: 2, asking_id: 1, created_at: "2016-12-13 15:07:08", updated_at: "2016-12-13 15:07:08"> #<Asking id: 1, content: "MyText", fromlang: "MyString", tolang: "MyString", usepoint: 1, finished: false, title: "MyString", deadline: nil, user_id: 1, created_at: "2016-12-13 15:07:08", updated_at: "2016-12-13 15:07:08"> #<User id: 2, email: "shiba.hayato2@docomo.ne.jp", created_at: "2016-12-13 15:07:08", updated_at: "2016-12-13 15:07:08", provider: nil, uid: nil, name: "Shiruba", occupation: "大学生", age: 10, sex: "男性", content: "heyheyheyeheyeheye", skill: "日本語検定3級", picture: "/assets/default_user.jpg", point: 500, country: "Japan", language1: "Japanese", language2: "Korea", language3: "English"> #<User id: 1, email: "shiba.hayato1@docomo.ne.jp", created_at: "2016-12-13 15:07:08", updated_at: "2016-12-13 15:07:08", provider: nil, uid: nil, name: "Shiruba", occupation: "大学生", age: 10, sex: "男性", content: "heyheyheyeheyeheye", skill: "日本語検定3級", picture: "/assets/default_user.jpg", point: 500, country: "Japan", language1: "Japanese", language2: "Korea", language3: "English"> #<ActiveRecord::Relation [#<Undertaking id: 1, title: "MyString", content: "MyText", result: false, user_id: 2, asking_id: 1, created_at: "2016-12-13 15:07:08", updated_at: "2016-12-13 15:07:08">]> F Failures: 1) comment can create comment Failure/Error: <%= @undertaking.id %> ActionView::Template::Error: undefined method `id' for nil:NilClass and this below is undertaking_controller.rb. class UndertakingController < ApplicationController def show @undertaking=Undertaking.find(params[:id]) @comment=Comment.new do |c| c.user=current_user end end end and this below is undertaking/show.html.erb. <%= @undertaking.id %> Why do I have the error? Why @undertaking is nil in view although Undertaking.first is not nil in spec/features/comment_spec.rb?Please help me. |
Form URL without id parameter? Posted: 13 Dec 2016 07:22 AM PST I have a form: form_for :comment, url: comment_path, method: :post do |f| After rendering, this becomes <form action="/comments/1" accept-charset="UTF-8" method="post"> I would expect the action to be only "/comments" without the id, because that is the actual path for creating a new comment. And of course I get a nice error message saying that my path is invalid: No route matches [POST] "/comments/1" ... comments_path GET /comments(.:format) comments#index POST /comments(.:format) comments#create ... What am I doing wrong that puts that id into the action? |
How to gzip html documents before uploading to S3 using CarrierWave? Posted: 13 Dec 2016 07:07 AM PST I have a rails model with an attachment (html document). When creating a new attachment and uploading to s3 using fog, I would like to compress the document with gzip before uploading to s3, to save space and upload time. How can I accomplish this? |
LogStash error - Missing jruby-win32ole gem Posted: 13 Dec 2016 07:26 AM PST I have a new plugin file i did for LogStash, in which i am calling an external C# dll i have made. (Noob in both c# and ruby, So bare with me) In the plugin, I'm trying to require the following: require "logstash/outputs/base" require "logstash/namespace" require "win32ole" and i'm getting the following error: !!!! Missing jruby-win32ole gem: jruby -S gem install jruby-win32ole And: Trying to load the newPlugin output plugin resulted in this error: no such file to load -- jruby-win32ole" Using version: 5.1.1 I tried different ways to solve this (mostly guessing), And non succeeded. Any help would be appreciated! |
Test if someone is logged out on another device Posted: 13 Dec 2016 06:18 AM PST we are using Rails and Devise, and I want to test when a user changes their password, that they are logged out on every device, except for the which he does the password change with. Manually I would test it like that: Log in with browser A Log in with browser B Change password with A Click something with browser B and see that you are not logged in anymore. How to test this automatically? |
Test failed with nested table: couldn't find SharedList with id Posted: 13 Dec 2016 08:15 AM PST I am using Rails 5.001 and I want to test a controller-function from shared_list. Shared_list is nested under shopping_list. shared_lists_controller_test.rb class SharedListsControllerTest < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers include Warden::Test::Helpers setup do new_shopping_list = shopping_lists(:shopping_list_drogerie) @heikoSharedList = shared_lists(:shared_list_heiko) @heiko = users(:user_heiko) end test "should get edit" do login_as(@heiko) @heiko.confirmed_at = Time.now get edit_shared_list_url(@heikoSharedList.shopping_list.id, @heikoSharedList) assert_response :success end However when I run the test, I get this error message: Error: SharedListsControllerTest#test_should_get_edit: ActiveRecord::RecordNotFound: Couldn't find SharedList with 'id'=102138810 test/controllers/shared_lists_controller_test.rb:49:in `block in <class:SharedListsControllerTest>' Does somebody know what went wrong and how to fix this? My fixtures look like this: shared_lists shared_list_heiko: user: user_heiko shopping_list: shopping_list_drogerie created_at: <%= Time.now %> updated_at: <%= Time.now %> shopping_lists shopping_list_drogerie: user: user_heiko name: Drogerie created_at: <%= Time.now %> updated_at: <%= Time.now %> model/list_item.rb class ListItem < ApplicationRecord # db associations belongs_to :shopping_list has_many :shopping_items # validations validates :shopping_list, :presence => true validates :name, presence: true, allow_blank: false end model/shopping_list.rb class ShoppingList < ApplicationRecord # db associations belongs_to :user # if a shopping list is deleted, also delete information about all items on the list has_many :list_items, :dependent => :destroy # if a shopping list is deleted, also delete information about who it was shared with has_many :shared_lists , :dependent => :destroy has_many :shared_with_users,through: :shared_lists, :source => :user has_many :invitation has_one :appointment # validations validates :user, :presence => true validates :name, presence: true, allow_blank: false, uniqueness: {scope: :user_id} end |
Could someone explain the following Ruby on Rails error? Posted: 13 Dec 2016 07:26 AM PST LoadError in CandidatesController#create Unable to autoload constant Usermailer , expected Z:/railsassignment/student/app/mailers/usermailer.rb to define it When I submit a form I get the error above. The form processes a record and the candidate is added to the database however the welcome email I'm trying to send to the newly registered candidate doesn't send, and the error above prevents the user from proceeding. Candidates Controller def create @candidate = Candidate.new(candidate_params) respond_to do |format| if @candidate.save Usermailer.welcome(@candidate).deliver_now ***<-- Error highlights this line*** format.html { redirect_to @candidate, notice: 'User was successfully created.' } format.json { render :show, status: :created, location: @candidate } else format.html { render :new } format.json { render json: @candidate.errors, status: :unprocessable_entity } end end end usermailer.rb Z:/railsassignment/student/app/mailers/usermailer.rb (usermailer directory) class UserMailer < ActionMailer::Base default from: "from@example.com" def welcome(candidate) @candidate = candidate mail(:to => candidate.can_email, :subject => "Welcome to EmployeMe.com, You have registered successfully!") end end Should you need to see any more of the files drop me a comment and I'll be quick to add them to the question. |
Ruby on rails : send_file returns a page full of bytes Posted: 13 Dec 2016 06:26 AM PST I'm simply trying to download a file from a controller (in order to manage authorizations) and the only result I get is a page full of bytes. I tried to set different configurations in the production.rb and environment.rb (uncomment X-sendfile, etc...), I didn't find another similar issue as well. If I delete the :path and :url parameter from my send_file method in my MemberFile model, it works fine but obviously files are public and that's not what I want. Authorizations are managed by a controller. I expect the exact same result as what happens when the file is public... Thank you for your help ! member_file.rb class MemberFile < ActiveRecord::Base belongs_to :member validates :member_id, presence: true has_attached_file :uploaded_file, :url => "/member_files/get/:id", :path => "#{Rails.root}/app/assets/test_member_files/:member_id/:id/:basename.:extension" validates_attachment :uploaded_file, content_type: { content_type: ["image/jpeg", "image/gif", "image/png", "application/pdf"] } Paperclip.interpolates :member_id do |attachment, style| attachment.instance.member_id end end member_file_controller.rb def show @member_file = MemberFile.find(params[:id]) authorize! :upload_files, @member_file.member send_file @member_file.uploaded_file.path, :type => @member_file.uploaded_file_content_type end routes.rb get 'member_files/get/:id' => 'member_files#show' Download link <td><%= link_to f.uploaded_file_file_name, f.uploaded_file.url, action: "download" %></td> (with our without action: "download" doesnt change anything) result Page full of bytes |
rspec , undefined method `id' for nil:NilClass Posted: 13 Dec 2016 08:08 AM PST feature "comment" do given(:user) do build(:user) end background do user1=create(:user) user1.id=1 login_as(user1) end scenario "can create comment" do @undertake=create(:undertake) visit undertake_path(@undertake) within("form#undertake-form-test") do fill_in "content" , with: "heyheyhey" end click_button 'send-btn' expect(page).to have_content 'heyheyhey' end end This is spec/features/comment_spec.rb. and this below is controllers/undertakes_controller.rb. class UndertakesController < ApplicationController def show @undertake=Undertake.find_by(id: params[:id]) @comment=current_user.comments.new end and this below is views/undertakes/show.html.erb. <p><%= @undertake.id %></p> and spec/factories/undertakes.rb. FactoryGirl.define do factory :undertake do association :ask association :user id 1 user_id 2 ask_id 1 title "MyString" content "MyText" result false end end routes.rb resources :asks , except:[:edit, :update] do resources :undertakes , only:[:create , :show , :destroy] , shallow: true do resources :comments , only:[:create] end end Now, why do I have error ActionView::Template::Error:undefined method id for nil:NilClass . Please help me. |
How can I give all users access to a read-only ‘sample’ in Ruby on Rails? Posted: 13 Dec 2016 05:25 AM PST I'm working on fairly standard Ruby on Rails app where users have many studies . When a user signs up, I would like them to have a sample study as an example, similar to how Trello gives you a sample board on sign up. My current approach is to deep_clone Study.first on registration and assign ownership to the current user. This means new users can edit their clone of the sample study and no-one else can see their changes. This works fairly well however it has now become quite complicated to clone studies as my associations are a lot more complex. To simplify, I would like to change my approach for the sample study. Instead of cloning, I now want to give everyone access to the first study in the database, but read-only. Studies have a few views, e.g. users can change questions, participants, settings, add tags, etc. They should be able to see existing questions, participants, settings, and tags, but not add, remove, or edit them for this sample study. I believe I need to: - Figure out how to make
Study.first show up for everyone in all the right views without it actually being owned by current_user - Make this study read-only for everyone except me
What's a good approach for doing this in Rails? |
How to add checkout state conditionally in spree Posted: 13 Dec 2016 05:13 AM PST Spree has the following code in order.rb checkout_flow do go_to_state :address go_to_state :delivery go_to_state :payment, if: ->(order) { order.payment_required? } go_to_state :confirm, if: ->(order) { order.confirmation_required? } go_to_state :complete remove_transition from: :delivery, to: :confirm end I want to add delivery state to order only if some condition is true. Something like insert_checkout_step :delivery, after: :address, if: :some_condition I didn't find any such thing in spree docs |
Doorkeeper AccessToken: undefined method `application_id=' Posted: 13 Dec 2016 05:09 AM PST I'm using remote MS SQL DB on my Rails app. The authentication is provided by doorkeeper gem. I created all the necessary for doorkeper tables (oauth_access_grants , oauth_access_tokens , oauth_applications ) I execute login in doorkeeper config file like: resource_owner_from_credentials do |routes| user = User.find_for_database_authentication(email: params[:email]) if user && user.valid_for_authentication? { user.valid_password?(params[:password]) } user else raise Doorkeeper::Errors::DoorkeeperError.new('invalid_resource_owner') end end When email/password is incorrect I get Doorkeeper error as expected. But when credentials are valid I get an exception: NoMethodError: undefined method `application_id=' for #<Doorkeeper::AccessToken > ActiveRecord::UnknownAttributeError: unknown attribute: application_id Although my oauth_access_tokens contains application_id int field |
Undefined method when saving form Posted: 13 Dec 2016 06:30 AM PST I am using Wicked to create a multi page webform. However, i need to use multiple tables in that form. I succeed using one and have gotten the page for the second table to show up nicely. However, when i try to save it, it gives this error: NoMethodError in Enquirys::StepsController#update undefined method `needed' for #<Enquiry:0x007fa4530e4cb0> I have been messing around with it some time now, but without succes. Because i have a lot of code and no clue where to look anymore, i added the important stuff in this gist: https://gist.github.com/GroeGIT/f22bd079814df2c0acc8430c4db520a7 Can anyone help me out with this, or doesn't Wicked support multi page forms with different tables? Thanks Models class Enquiry < ActiveRecord::Base #ophalen van andere tabellen voor het formulier. Has_many is 1 op veel relatie #accepts_nested_attributes Nested attributes allow you to save attributes on associated records through the paren # de dere regel zorgt ervoor dat de maatregelen worden opgehaald via de tussentabel enquiry_measures. has_many :enquiry_measures, :class_name => 'EnquiryMeasure' #, inverse_of: :Enquiry accepts_nested_attributes_for :enquiry_measures, :allow_destroy => false has_many :measures, -> { uniq }, :class_name => 'Measure', :through => :enquiry_measures, dependent: :destroy has_many :controls, :class_name => 'Control' #, inverse_of: :Enquiry has_many :applicants, :class_name => 'Applicant' #, inverse_of: :Enquiry has_many :agrees, :class_name => 'Agree' #, inverse_of: :Enquiry has_many :signatures, :class_name => 'Signature' #, inverse_of: :Enquiry accepts_nested_attributes_for :signatures, :allow_destroy => false has_many :tools, :class_name => 'Tool' #, inverse_of: :Enquiry # 28-11 MG de pagina's die in het form worden gebruikt. cattr_accessor :form_steps do %w(basic when measurements) end attr_accessor :form_step validates :Reference, :Location, presence: true, if: -> { required_for_step?(:basic) } validates :Amount, :Date, presence: true, if: -> { required_for_step?(:when) } validates :needed, presence: true, if: -> { required_for_step?(:measurements) } #validates :needed, :measurement, presence: true, if: -> { required_for_step?(:createmeasures) } def required_for_step?(step) return true if form_step.nil? return true if self.form_steps.index(step.to_s) <= self.form_steps.index(form_step) end end class EnquiryMeasure < ActiveRecord::Base belongs_to :enquiry, :class_name => 'Enquiry' #, inverse_of: :enquiry_measures validates_presence_of :enquiry has_many :measure, :class_name => 'Measure' end Controllers: Enquiry controller: class EnquirysController < ApplicationController before_action :set_enquiry, only: [:show, :edit, :update, :destroy] before_action :set_measurement, only: [:show, :edit, :update] def index # Normally you'd have more complex requirements about # when not to show rows, but we don't show any records that don't have a name @enquirys = Enquiry.where.not(reference: nil) #voor het toevoegen van maatregelen. test! @measurements = Measure.where.not(measurement: nil) #@enquirymeasure = EnquiryMeasure.where.not(enquiry_measure_id: nil) end def new @enquiry = Enquiry.new #voor het toevoegen van maatregelen. test! @enquiry_measure = EnquiryMeasure.new @measurement = Measure.new end def create @enquiry = Enquiry.new #@enquiry_measure = EnquiryMeasure.new @enquiry.enquiry_measures.build#(:enquiry_id => :id) @enquiry.save(validate: false) #@enquiry_measure.save(validate: false) redirect_to enquiry_step_path(@enquiry, Enquiry.form_steps.first) @measurement = Measure.new @measurement.save(validate: false) end def show @enquiry = Enquiry.find(params[:enquiry_id]) @measurement = Measure.find(params[:id]) end def destroy @enquiry.destroy respond_to do |format| format.html { redirect_to enquirys_url } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_enquiry @enquiry = Enquiry.find(params[:id]) end def set_measurement @measurement = Measure.find(params[:Measure.id]) end # Never trust parameters from the scary internet, only allow the white list through. #Nodig voor het opslaan en tonen van items! alle weer te geven dingen dienen in de params te staan. def enquiry_params params.require(:enquiry).permit(:Reference, :Location, :Date, :Time, :Amount, measure_attributes: [:measurement, :type, :valid_from, :valid_to] ) #nquiry_measures_attributes: [ :done, :responsible, :needed] end end Step_controller: class Enquirys::StepsController < ApplicationController include Wicked::Wizard steps *Enquiry.form_steps def show @enquiry = Enquiry.find(params[:enquiry_id]) #@enquiry_measures = EnquiryMeasure.find(params[:enquiry_measure_id]) render_wizard end def update @enquiry = Enquiry.find(params[:enquiry_id]) @enquiry.update(enquiry_params(step)) #werkt niet, could not find EnquiryMeasure with 'id'= #@enquiry_measure = EnquiryMeasure.find(params[:enquiry_measure_id]) #@enquiry_measure.update(enquiry_measure_params(step)) render_wizard @enquiry end private def enquiry_params(step) permitted_attributes = case step when "basic" [:Reference, :Description, :Location] when "when" [:Amount, :Date] when "measurements" [:responsible, :needed, :done] # when "createmeasures" # [:measurement] end params.require(:enquiry).permit(permitted_attributes).merge(form_step: step) #params.require(:enquiry_measures).permit(permitted_attributes).merge(form_step: step) end end The view in question: <%= form_for @enquiry, method: :put, url: wizard_path do |f| %> <% if f.object.errors.any? %> <div class="error_messages"> <% f.object.errors.full_messages.each do |error| %> <p><%= error %></p> <% end %> </div> <% end %> <fieldset> <legend>Informatie</legend> <div> <%= f.label :reference %> <%= f.text_field :Reference, disabled: true %> </div> </fieldset> <%# Code voor de Measurements. %> <fieldset> <legend>Maatregelen</legend> <%= f.fields_for :enquiry_measures do |enquiry_measures| %> <%# enquiry_measures.fields_for :measure do |measures| %> <% if false %> <div> <%= f.label :Maatregel %> <br/> <%= collection_select(:measure, :enquiry_id, Enquiry.all, :id, :measurement) %> <%# http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select -%> <%# uitgebreider, bovenstaande zou goed moeten zijn(8-12 MG) collection_select :measurement, :enquiry_measures, measurement.select(:measurement).uniq.order('measurement ASC'), :measurement, :measurement, {:prompt => 'kies een maatregel'}, {:name => 'select_measurement'} %> </div> <% end %> <div> <%# test met enquiry_measures ipv f.label 7-12 MG%> <%= f.label :Gereed %> <br/> <%= enquiry_measures.check_box :done %> </div> <div> <%= f.label :Verantwoordelijke %> <br/> <%= enquiry_measures.text_field :responsible %> </div> <div> <%= f.label :Benodigd %> <br/> <%= enquiry_measures.check_box :needed %> </div> <div> <%= f.submit 'Next Step' %> <%# 24-11 MG knop die je terug stuurt naar de homepage %> <%= button_tag "Annuleren", :type => 'button', :class => "subBtn", :onclick => "location.href = '#{root_path()}'" %> </div> <%# end of enquiry_measures.fields_for :measure, END Tag nog plaatsen! %> <% end %> <%# end of f.fields_for :enquiry_measures %> </fieldset> <% end %> |
bundle exec rake db:setup, Rake tasks not supported by 'username' adapter Posted: 13 Dec 2016 04:49 AM PST When I try to run bundle exec rake db:setup ,It gives me this error and when I change the adapter to my username I got the same error PG::InsufficientPrivilege: ERROR: permission denied to create database : CREATE DATABASE "freelance_camp_documents_development" ENCODING = 'unicode' Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"freelance_camp_documents_development"} rake aborted! ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied to create database : CREATE DATABASE "freelance_camp_documents_development" ENCODING = 'unicode' /usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec' /usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute' /usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log' /usr/local/share/gems/gems/activesupport- I can't put the whole error here and here is the database.yml code default: &default adapter: postgresql encoding: unicode # For details on connection pooling, see rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: freelance_camp_documents_development test: <<: *default database: freelance_camp_documents_test production: <<: *default database: freelance_camp_documents_production username: freelance_camp_documents password: <%= ENV['FREELANCE_CAMP_DOCUMENTS_DATABASE_PASSWORD'] %> |
Please help us to Improve rails query to reject current user items in the list Posted: 13 Dec 2016 05:02 AM PST I have a query that will fetch the all images and filter the current user uploaded, rated and favorite images. But this is consuming more time. Please see below query and sugget a best query to reduce execution time. @images = Image.active_images.order('images_order') .where.not(user_id: current_user.id) .select{|item| item.ratings.where(user_id: current_user.id).count <= 0 } .select{|item| item.favorite_images.where(user_id: current_user.id).count <= 0 } |
Getting "Sender Address Rejected" Error in OpenProject Email Notification settings in configuration.yml file Posted: 13 Dec 2016 03:56 AM PST I am trying to setup 'Openproject' management tool in Amazon AWS EC-2 instance. Everything is done and I am able to access openproject home page on entering the IP address of EC-2, but while registering for new user I am getting an error page. After checking production.log file in the openproject files I am seeing the following error. Net::SMTPFatalError (553 5.7.1 : Sender address rejected: not owned by user user@jayrobotix.com Here are the settings in my configuration.yml file. default: # Outgoing emails configuration (see examples above) email_delivery_method: :smtp smtp_address: smtp.jayrobotix.com smtp_port: 587 smtp_domain: jayrobotix.com smtp_authentication: :plain smtp_user_name: "user@jayrobotix.com" smtp_password: "password" smtp_enable_starttls_auto: false The smtp_user_name and smtp_password is my username and password for my email server. I am following the manual given in openproject.org website for configuring openproject in linux. Please help me in setting up this. .. Thanks |
How alias_method work in ruby. How can I use it to achieve DRY? Posted: 13 Dec 2016 04:16 AM PST I saw this line of code in an application but was unable to find the method get_accounts in whole application. alias_method :get_accounts, :get_list_of_records |
Mailgun account disabled soon after signing up Posted: 13 Dec 2016 04:11 AM PST I was trying to test/explore mailgun for email service. Soon after signing up I am getting the following text Then I thought that it could be because I haven't verified any domain. But, when I try to add a domain I am getting the following msg: And when I tried to send email, using gem 'mailgun-ruby', '~>1.1.2' and mailgun sandboxdomain , from ruby console I have the following errors displayed Seems like account disabled is the issue here. I had just signedup and my account is disabled. Any help on this? |
How to get rid of surrounding quotes in Rails? Posted: 13 Dec 2016 04:01 AM PST I'm having problems with weird behaviour in RoR. I'm having a Hash that i'm converting to json using to_json() like so: data = Hash.new # ... data = data.to_json() This code appears inside a model class. Basically, I'm converting the hash to JSON when saving to database. The problem is, the string gets saved to database with its surrounding quotes. For example, saving an empty hash results in: "{}" . This quoted string fails to parse when loading from the database. How do I get rid of the quotes? The code is: def do_before_save @_data = self.data self.data = self.data.to_json() end EDIT: Due to confusions, I'm showing my entire model class
require 'json' class User::User < ActiveRecord::Base after_find { |user| user.data = JSON.parse(user.data) } after_initialize { |user| self.data = Hash.new unless self.data } before_save :do_before_save after_save :do_after_save private def do_before_save @_data = self.data self.data = self.data.to_json() end def do_after_save self.data = @_data end end The data field is TEXT in mysql. |
Capistrano SQLite3::SQLException: no such table: users Posted: 13 Dec 2016 03:25 AM PST Ubuntu 16, ruby, 3.2, framework Sinatra. After cap deploy not running migration on production. I deploy with command cap deploy production my project to remote server. In app.rb connection setting for db: #app.rb require "sinatra" require "pry" require "sinatra/activerecord" require 'sinatra/flash' require 'sinatra/base' require "./models/user" require "./models/game_counter" require "./models/stash" require "json" require "pony" require 'logger' enable :static enable :sessions set :public_folder, File.dirname(__FILE__) + '/assets' set :database, { adapter: "sqlite3", database: "sudoku_database.sqlite3" } Gemfile gem "rake" gem "heroku" gem "sinatra" gem "sinatra-activerecord" gem "sinatra-flash" gem "sqlite3" gem "pg" gem "bcrypt" gem "pry" gem "pony" gem "capistrano", '~> 3.1.0' gem "capistrano-bundler", '~> 1.1.2' gem 'passenger' I installed sqllite on remote server. Installed and customized capistrano. config/deploy.rb lock '3.4.0' set :application, 'projectname' set :repo_url, 'git@github.com:user/projectname.git' set :deploy_to, '/home/deploy/projectname' set :linked_dirs, %w{ log } namespace :deploy do desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do execute :touch, release_path.join('tmp/restart.txt') end end after :publishing, 'deploy:restart' after :finishing, 'deploy:cleanup' end config/production.rb set :stage, :production server '188.177.76.190', user: 'deploy', roles: %w{web app db}, port: 2503 When i run web site in browser, in logs nginx display error: 2016-12-13 10:40:58 - ActiveRecord::StatementInvalid - SQLite3::SQLException: no such table: users: SELECT "users".* FROM "user Help me please, can`t undestand why dont running migration for database on production and how me solve this problem? |
Rspec, fail testing date Posted: 13 Dec 2016 04:16 AM PST I'm trying to test this : it "should calculate the max_validation_deadline" do tasting = Tasting.create!(valid_attributes) expect ( tasting.max_validation_deadline.to_s ).to eq(today_plus_one.to_s) end But it fails. When I'm debugging it I'm having this. (byebug) tasting.max_validation_deadline.to_s "2016-12-13 01:00:00 UTC" (byebug) today_plus_one.to_s "2016-12-13 01:00:00 UTC" (byebug) expect ( tasting.max_validation_deadline.to_s ).to eq(today_plus_one.to_s) *** ArgumentError Exception: bad value for range Why does it fail saying bad value for range as I'm passing two strings ? Edit Here is a full byebug when I'm not testing with to_s . bundle exec rspec spec/models/tasting_spec.rb ........ [76, 85] in server/spec/models/tasting_spec.rb 76: end 77: 78: it "should calculate the max_validation_deadline" do 79: tasting = Tasting.create!(valid_attributes) 80: byebug => 81: expect ( tasting.max_validation_deadline ).to eq(today_plus_one) 82: end 83: 84: it "should calculate the current_opened_places" do 85: tasting = Tasting.create!(valid_attributes) (byebug) expect ( tasting.max_validation_deadline ).to eq(today_plus_one) *** NoMethodError Exception: undefined method `to' for Tue, 13 Dec 2016 01:00:00 UTC +00:00:Time nil (byebug) |
rails how to call a controller action on running local server from command line [duplicate] Posted: 13 Dec 2016 03:15 AM PST This question already has an answer here: I read that it is not a good practice. But I'm ok with it. I am now calling the action from the browser url with a route to the action but I would like to be able to call directly from the command line without opening the browser. I do not want to call the action when I start the server, as I may need to run different actions and/or several times in each session. |
How to view flask params in browser [duplicate] Posted: 13 Dec 2016 03:23 AM PST This question already has an answer here: In Ruby on Rails I can type fail in the controller then go to the browser and view the list of params. How can I do that in flask(python) ? |
No comments:
Post a Comment