Don't know how to build task 'symlink_directories' Posted: 26 Dec 2016 07:36 AM PST After upgrading a rails project, I'm trying to deploy with capistrano and suddenly getting this error: Tasks: TOP => deploy:restart (See full trace by running task with --trace) The deploy has failed with an error: Don't know how to build task 'symlink_directories' (see --tasks) My Capfile : # Load DSL and set up stages require "capistrano/setup" # Include default deployment tasks require "capistrano/deploy" require "capistrano/scm/git" install_plugin Capistrano::SCM::Git require "rvm1/capistrano3" require "capistrano/bundler" require "capistrano/rails/assets" require "capistrano/rails/migrations" require "capistrano/rails" require "capistrano/passenger" # Load custom tasks from `lib/capistrano/tasks` if you have any defined Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } Gemfile.lock capistrano related gems: capistrano (3.7.1) capistrano-harrow capistrano-bundler (1.2.0) capistrano (~> 3.1) capistrano-harrow (0.5.3) capistrano-passenger (0.2.0) capistrano (~> 3.0) capistrano-rails (1.2.1) capistrano (~> 3.1) capistrano-bundler (~> 1.1) rvm1-capistrano3 (1.4.0) capistrano (~> 3.0) capistrano (>= 3.5.0) capistrano (~> 3.7) capistrano-bundler (~> 1.2) capistrano-passenger capistrano-rails (~> 1.2) rvm1-capistrano3 |
How to solve undefined method in rails 5 Posted: 26 Dec 2016 07:21 AM PST First, sorry for my english, I'm make a forum from scratch and I'm currently having an issue when I generate the post form Showing D:/Lab/Rails/Forum/app/views/forumposts/_form.html.erb undefined method `forumposts' for nil:NilClass Model forumtopic.rb belongs_to :forumforum has_many :forumposts, :dependent => :destroy belongs_to :user Model forumpost.rb belongs_to :forumtopic belongs_to :user forumposts_controller.rb def create @topic = Forumtopic.friendly.find(params[:forumtopic_id]) @forumpost = @topic.forumposts.create(params.require('forumpost').permit(:content)) if @forumpost.save redirect_to forumtopic_path(@topic) else render 'new' end end Views/forumposts/_form.html.erb <% if signed_in? %> <div class="wrapper"> <div class="post_form"> <%= simple_form_for([@topic, @topic.forumposts.build]) do |f| %> <div> <%= f.text_area :content, class: "post-textarea", placeholder: "Message", cols: 50, rows: 4 %> </div> <div> <%= f.submit "Save ", class: "post-button" %> </div> <% end %> </div> </div> <% end %> views/forumtopics/show.html.erb <div class="row"> <div class="col-md-12"> <div class="answer"> <%= @forum_topic.forumposts.count %> answers </div> **OK** </div> </div> <%= render @forum_topic.forumposts %> **OK** <% render 'forumposts/form' %> **Problem** When I do that in console, I get all the topic's post: @topic = Forumtopic.first @topic.forumposts Please help thank you |
How store business logic into database? Posted: 26 Dec 2016 07:10 AM PST I'd like to allow users to define simple business logic such as: if (x and y) then ... if (z or w) then ... Let me put it concretely: I'm developing a HR module that answers if applicants fulfill some requirements, to be defined by users. Such requirements can be defined around logical operators: (Must be 18 years old) or (under 18 years and must have parents permission) Is putting this kind of logic inside the database ok? I think it is, but I'm afraid of spending time on this and find that its a poor approach. |
Rails associacions Posted: 26 Dec 2016 06:51 AM PST I'm am new in Ruby on Rails developing. Let's go straight to the point. I have four models User, exercise, result, users_exercise. I was struggling with that problem almost 3 hours now... What i am trying to do is a build associacion between that tables which allow me to make ORM statements like this: User.first.exercises.first.barbell_push etc. What i want to get is every exercise for user, then get a barbell_push result. UserExercise model: create_table :users_exercises do |t| t.integer :user_id t.integer :exercise_id t.date :date t.timestamps null: false end And associacion (current one) class UsersExercise < ActiveRecord::Base belongs_to :user belongs_to :exercise end Exercise and associacions: create_table :exercises do |t| t.integer :dead_lift_id t.integer :barbel_push_id t.integer :dumbbels_curl_id t.timestamps null: false end class Exercise < ActiveRecord::Base has_many :dead_lift, class_name: 'Result', foreign_key: 'exercise_id' has_many :barbel_push, class_name: 'Result', foreign_key: 'exercise_id' has_many :dumbbell_curl, class_name: 'Result', foreign_key: 'exercise_id' has_many :users_exercises, dependent: :destroy has_many :users, through: :users_exercises end Result: create_table :results do |t| t.integer :reps t.integer :weight t.integer :exercise_id t.timestamps null: false end class Result < ActiveRecord::Base belongs_to :exercise end And user associacions: class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:google_oauth2] ROLES = [:admin, :user, :trainer, :dietician] has_many :sent_messages, :class_name => "Message", :foreign_key => "sender_id" has_many :received_messages, :class_name => "Message", :foreign_key => "receiver_id" has_many :users_exercises has_many :exercise, through: :users_exercises end Every help will be appreciate. Because i rly can't continue without that. Cheers! |
What is the best HTTP status code for blocked user profile in rails api? Posted: 26 Dec 2016 06:46 AM PST I wrote an API for social app in Rails. This app likes Facebook, users can block other users. If user A block user B, user B can't view profile page of user A. So what is the best HTTP code status I should return: 404, 403, 204 or 200(render nothing) ? |
Accessing locale files from JS Posted: 26 Dec 2016 06:35 AM PST I have a project where I have different localization files, and so I need to access the insides of ja.yml file in JavaScript. I ve done a little research and found one solution that is: in application_helper.rb file i add a method def current_translations @translations ||= I18n.backend.send(:translations) @translations[I18n.locale] end and from the application.html.slim file I call that method to load it into the variable: script[type="text/javascript"] | window.I18n = = current_translations.to_json so when i try to access something like I18n.ja.activerecord.models.user from any of js files i get the error that says unidentified method ja of null, which means that the locale file that should be loaded into the I18n variable is not loaded properly, so when i try to console.log it just sends me an empty object. Is there smth that i missed? Thanks in advance |
Rails API versioning and forum_url Posted: 26 Dec 2016 07:29 AM PST I try to add the location header to my versioned API. NoMethodError (undefined method `forum_url' for #<V1::ForumsController:0x00000004fabaa0>):app/controllers/v1/forums_controller.rb:24:in `create' How can I override the render location: forum helper to use v1_forum_url instead of forum_url ? |
run jquery/javascript after change page Posted: 26 Dec 2016 05:13 AM PST in rails, i have a nested attribute for selection, different dropdown of same id & name. I'm forming an array for each id of selected options through the javascript function 'hoho'. There is no blank option so the options should be selected once page is loaded. i wanted to immediately form the array once i navigated into the dropdown page, but i only get the array by reloading the page. is it due to the onload code or turbolink issue with rails? seen somewhere maybe it is related to some page:change code instead? please advise.. im using mozilla if that will be helpful, thanksss rails html view <select name="variant[option_value_ids][]" onchange="hoho()" id="variant_option_value_ids"> <option value="69">apple</option> <option value="70">orange</option> </select> <select name="variant[option_value_ids][]" onchange="hoho()" id="variant_option_value_ids"> <option value="69">apple</option> <option value="70">orange</option> </select> javascript function hoho() { var foo = []; $("[id^=variant_option_value_ids] option:selected").each(function(){ foo.push($(this).val()); }); } window.onload = hoho; |
Not getting real facebook friends Posted: 26 Dec 2016 04:50 AM PST When I test my app using test users created through the facebook developer section, facebook friends of those test users do get fetched, but not when I use a real account with real friends. Real facebook accounts are users of the facebook app because they used facebook omniauth to get registered on my website. I don't understand why this is happening. Does anyone have any experience facing this kind of an issue? def get_facebook_friends if current_user.identities.where(provider: 'facebook').exists? #just use user' existing facebook credentials identity = current_user.identities.where(provider: 'facebook').first facebook = Koala::Facebook::API.new(identity.token) @ffriends = facebook.get_connections("me", "friends?fields=id,name,picture.type(large)") @number_of_friends = @ffriends.length session['ffriends'] = @ffriends session['number_of_friends'] = @number_of_friends @facebook_main_2 = "block" @facebook_main_1 = "none" binding.pry else #have user sign_in to facebook session['redirect_to'] = get_facebook_friends_path redirect_to user_facebook_omniauth_authorize_path end end |
Proper place to put Pattern initialization code in Rails Posted: 26 Dec 2016 05:12 AM PST I am implementing Repository pattern, so that my DB implementation can change in future. class Repository def self.repositories @repositories ||= {} end def self.register(type, repo) repositories[type] = repo end def self.for(type) repositories[type] end end I register for a repository using Repository.register(:friend_request, GraphRepository::FriendRequestRepository) So in my app everywhere I use Repository.for(:friend_request) to get the DB implementation class GraphRepository::FriendRequestRepository in this case, and then I can call whatever method I like on it, and in future GraphRepository::FriendRequestRepository can change to some other class but my app code everywhere will remain same. PROBLEM FACED Where to put code?? Repository.register(:friend_request,raphRepository::FriendRequestRepository) I placed it in initializer, but during run time on first server/controller action sometime I am getting expected value for Repository.for(:friend_request) , i.e GraphRepository::FriendRequestRepository , but then I am getting nil. I placed this code in application.rb in config.after_initialize block. But the same thing happens. |
Cron Job using resque gem not working Posted: 26 Dec 2016 03:26 AM PST I am running a background job so that every time the address is updated it should be able to interact with another rails app by sending json data using Httparty. The Cron job created is class InvoiceGenerateJob < ActiveJob::Base queue_as :invoice_generate_queue def perform(*args) order_id = args[0] order = Order.find(order_id) if order if (['Notary', 'Attestation','Franking'].include? order.service.name) no_of_copies = ((order.answers.where(question_id: [37,15]).length > 0) ? order.answers.where(question_id: [37,15]).first.body : 0).to_i else no_of_copies = ((order.answers.where(question_id: [37,15]).length > 0) ? order.answers.where(question_id: [37,15]).first.body : 0).to_i + 1 end send_data = HTTParty.post('http://localhost:3001/api/v0/generate_invoice? key=docket', :body => { "id" => order.id, "txnid" => order.txnid, "service_name" => order.service.name, : "delivery_amount" => order.delivery_amount || '', "no_of_copies" => no_of_copies}.to_json, :headers => { 'Content-Type' => 'application/json'}) end end end I call this method in update address api def update_order_address response = Hash.new result = Hash.new @order = Order.where(txnid: params[:txnid]).first : : result['user_id'] = @order.user_id InvoiceGenerateJob(@order.id).perform_later response['result'] = result else response.merge! ApiStatusList::INVALID_REQUEST end render :json => response end when I try to test the job on the console by running InvoiceGenerateJob(Order.last.id).perform_later it gives me: undefined method `InvoiceGenerateJob' for main:Object My redis-server is on and my resque worker is running as well. What must be error.Please help me rectify it |
jQuery: Checking / Unchecking DOM Elements Posted: 26 Dec 2016 04:03 AM PST I've got the following script that gets executed via AJAX in Rails: It appears that only the first specified option (unchecking) works, the part inside the else statements does not work! <% if params[:type] == "switch" %> var obj = $('.<%= params[:name] %> a:not(.label) #myonoffswitch:checkbox'); <% if params[params[:name]] %> obj.prop('checked', false); <% else %> obj.prop('checked', true); <% end %> <% elsif params[:type] == "checkbox" %> <% if params[params[:name]] %> $('.<%= params[:name] %> a:not(.label)').remove(); $('.<%= params[:name] %>').prepend("<a data-remote='true' href='/update?name=<%= params[:name] %>&<%= params[:name] %>=true&type=checkbox'><i class='icon ion-android-checkbox-outline-blank' tabindex='0'></i></a>"); $('.<%= params[:name] %> a:not(.label) i').focus(); <% else %> $('.<%= params[:name] %> a:not(.label)').remove(); $('.<%= params[:name] %>').prepend("<a data-remote='true' href='/update?name=<%= params[:name] %>&<%= params[:name] %>=false&type=checkbox'><i class='icon ion-android-checkbox' tabindex='0'></i></a>"); $('.<%= params[:name] %> a:not(.label) i').focus(); <% end %> <% end %> DOM <div class="name flex"> <a data-remote="true" href="/update?name=name&name=false&type=switch"><div class="onoffswitch"> <input checked="" class="onoffswitch-checkbox" id="myonoffswitch" name="onoffswitch" type="checkbox"> <label class="onoffswitch-label" for="myonoffswitch"></label> </div> </a> <div class="label"> <a class="abc label" data-remote="true" href="/update?name=name&name=false&type=switch">ABC </a> <p class="abc labeltext">Lorem ipsum.</p> </div> </div> <div class="name1 flex"><a data-remote="true" href="/update?name=name1&name1=true&type=checkbox"> <i class="icon ion-android-checkbox-outline-blank" tabindex="0"></i></a> <div class="label"> <a class="abc label" data-remote="true" href="/update?name=name1&name1=false&type=checkbox">ABC </a> <p class="abc labeltext">Lorem ipsum.</p> </div> </div> However, I noticed that only if a checkbox or a switch is checked it gets unchecked, and if it is unchecked it will not change it's appearance (the DOM). What am I doing wrong? |
Increment a cookie value by 1 and then let to vote for other values (since the voting system is on an index page) Posted: 26 Dec 2016 02:59 AM PST In my app I use js-cookie . Is it possible to increment a cookie value by 1? This is my code: $(document).on('turbolinks:load', function () { var ii = 1; var i = parseInt(ii); Cookies.set('userHasVoted', i, {expires: 7}); $('.rateit-reset').remove(); $(this).parents().parents().parents('.casino-item').children('.rateit.rateit-font').first().attr('data-rateit-value'); $('.rateit-hover').click(function () { var rating = $(this).parents().attr('aria-valuenow'); var float_number = parseFloat(rating); var rating_form_input = $(this).parents().parents('.casino-item').children('.rating').children('.star_rating_form').children('.star-value'); var form_id = $(this).parents().parents('.casino-item').children('.rating').children('.star_rating_form').attr('id'); var $target = $(this).parents().parents().parents('.casino-item').children('.average-rating').children('span'); rating_form_input.val(float_number); if (Cookies('userHasVoted') > 1) { alert('You have already voted'); } else { $.ajax({ type: 'post', url: $('#' + form_id).attr('action'), data: $('#' + form_id).serialize() }).done(function (data) { $target.html(data.rating); ii++ }); } }) }); So, here I submit the form by clicking on a $('.rateit-hover') element. And I want a visitor(since I don't have any user) not to vote twice. But there is another problem. A rating system is on a casino index page, so I need that the other casinos could be still votable. If a cookie value will be incremented by 1, all other casinos won't be votable. Is there any solution of how to bypass this issue? Thanks. |
Rspec test error in devise session #create Posted: 26 Dec 2016 03:07 AM PST I implemented point system. User.point increases by 2 when he does login. My devise session controller is below. class Users::SessionsController < Devise::SessionsController after_action :add_point, only: [:create] # POST /resource/sign_in def create super end private def add_point resource.rewards.create(point: 2) end end and My spec/controllers/users_controller_spec.rb is below. RSpec.describe UsersController, type: :controller do describe 'adds 2 point with login' do before do @user=create(:user) end it 'adds 2 point in one day if two times login' do expect{login_user(@user)}.to change {@user.points}.by(0) end it 'adds 4 point in two day ' do expect{login_user(@user)}.to change {@user.points}.by(2) end end end When I did rspec command , I had this error. Failure/Error: expect{login_user(@user)}.to change {@user.points}.by(2) expected result to have changed by 2, but was changed by 0 I confirmed that @user.points increased by 2 in rails/console. Why do I have this error? Please tell me. |
"Could not find a JavaScript runtime". How do I install one? Posted: 26 Dec 2016 02:52 AM PST I am unable to start a rails server. Apparently I don't have a JavaScript runtime. $ rails s c:/Ruby22/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError) Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. I went to the link https://github.com/rails/execjs But I couldn't figure out what to do. So how exactly do I 'install' a JavaScript runtime? Also here is my GemFile: source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] |
Could not draw bounding box border in prawn Posted: 26 Dec 2016 02:59 AM PST How do i draw a border around bounding box with specific setting bounding_box([175, starting_y - 190], :width => 30.mm, :height => 17.mm) do stroke_color 'FFFF00' dash 10, space: 4 stroke_bounds end I would like to have border dotted for bottom alone, How will i have this? I tried searching in stroke, stroke_bounds, bounding_box of prawn document, i could not find anything |
What are the differences between Puma server and Ember server? [on hold] Posted: 26 Dec 2016 01:57 AM PST I'd like to build an web application whose frontend is developped by Angular2 and backend is developped by Rails. Someone said I can use rails s command to start a Puma server for the backend and ng serve to start a Ember server for the frontend. There is a proxy configuration for Ember server to access Puma server. I don't really konw the differences between these two servers. Could I start another Puma server for the frontend. If I could, how should I configure to achieve this? |
How to implement two-layered architecture in Rails [on hold] Posted: 26 Dec 2016 01:51 AM PST By two-layered architecture I mean two separate layers in application: Presentation layer (controllers and views) and Business layer (model as ActiveRecord classes and some business classes that provide interface for Presentation layer). By separation I mean that I can change the model as I want and leave the code in Presentation Layer untouched. For example, there was a problem in futurelearn.com when developers decided to split one big table for everything (single table inheritance) into separate tables: https://about.futurelearn.com/blog/refactoring-rails-sti. The problem was that all codebase was dependent on model and it was necessary to change code everywhere. Author of post, however, says few words about full separation when considers different options - development of API that let changes in model without changes in Presentation Layer. How can it look in Rails? Is it even possible? If yes, could you provide a simple example. |
paperclip save file without write access Posted: 26 Dec 2016 02:06 AM PST I notice that paperclip doesn't make thumb and other style images, and if I bundle exec rake RAILS_ENV=development paperclip:refresh:thumbnails CLASS=ListingImage I get Permission denied @ rb_sysopen - /home/deploy/sharetribeProd/sharetribe/public/system/images/34/original/93.png - skipping file. Here is mine dir listings. deploy@linestudio:~/sharetribeProd/sharetribe$ ls -la public/system/images/33 total 12 drwxr-xr-x 3 www-data www-data 4096 Dec 26 08:50 . drwxrwxrwx 5 www-data www-data 4096 Dec 26 08:53 .. drwxr-xr-x 2 www-data www-data 4096 Dec 26 08:50 original deploy@linestudio:~/sharetribeProd/sharetribe$ ls -la public/system/images/33/original/ total 12 drwxr-xr-x 2 www-data www-data 4096 Dec 26 08:50 . drwxr-xr-x 3 www-data www-data 4096 Dec 26 08:50 .. -rw-r--r-- 1 www-data www-data 2340 Dec 26 08:50 93.png I am not sure, what info I have to show more - help please. It is first time I see that error, looks like paperclip saves images without +w rules and then just cant get it for resize. I am close to remove whole droplet and install server again. Thanks for attention. P.S. Im using passenger + nginx. |
Mailboxer html formattting Posted: 26 Dec 2016 12:58 AM PST How can I allow Mailboxer gem to send HTML formatted messages? For example, I want the first message user A sends to user B to be pre-formatted with certain text and HTML tags. Currently any kind of markup is escaped.. |
I keep getting a NoMethodError Undefined method 'posts' Posted: 26 Dec 2016 12:20 AM PST I know a bit of Ruby and no other language. I'm now trying to learn how to use rails the tutorial I'm following doesn't show the same error that I got. I think it's because I'm using a different version of Ruby and Rails from the tutorials. >ruby -v => ruby 2.2.4p320 >rails -v => 5.0.1 Now, the tutorial is teaching me how to make a blog webapp thing. But I can't create a blog because every time I try to submit my entries I get an error. I'm very new to almost everything but basic ruby. Please help! This is my articles model: class Article < ActiveRecord::Base belongs_to :user has_many :comments validates :title, presence: true, length: {maximum: 50} validates :posts, presence: true end |
Rails prints the query result along with the object data in the view Posted: 25 Dec 2016 11:19 PM PST I want to create a notebook app in rails. I need to print all the notes in the index view, so below is code in haml. = @notes.each do |note| %h1= link_to note.title, note %p= time_ago_in_words(note.created_at) The problem is after the Note title and created time are displayed, the query result is printed at the end(Screenshot below). The issue persists only while printing all the notes at once using loop. Can't figure out what's the issue. Thanks in advance. |
Ruby - Cannot Load File (LoadError) Posted: 25 Dec 2016 10:07 PM PST I installed the ruby-aaws gem and I tried to run a sample script. I Get the following error. Is there something I am missing ?Thanks. 1. gem install ruby-aaws 2. amazon.rb require 'amazon/aws' require 'amazon/aws/search' include Amazon::AWS include Amazon::AWS::Search ASSOCIATES_ID = "************" KEY_ID = '**************' il = ItemLookup.new( 'ASIN', { 'ItemId' => 'B001COU9I6', 'MerchantId' => 'Amazon' }) rg = ResponseGroup.new( 'Medium' ) req = Request.new(KEY_ID, ASSOCIATES_ID) resp = req.search( il, rg) item_sets = resp.item_lookup_response[0].items item_sets.each do |item_set| item_set.item.each do |item| attribs = item.item_attributes[0] puts attribs end end (ERROR) $ ruby amazon.rb /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- iconv (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Library/Ruby/Gems/2.0.0/gems/ruby-aaws-0.8.1/lib/amazon/aws.rb:12:in <module:AWS>' from /Library/Ruby/Gems/2.0.0/gems/ruby-aaws-0.8.1/lib/amazon/aws.rb:7:in ' from /Library/Ruby/Gems/2.0.0/gems/ruby-aaws-0.8.1/lib/amazon/aws.rb:5:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in rescue in require' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in require' from amazon.rb:7:in `' |
How to use program to estimate which item has more score? [on hold] Posted: 25 Dec 2016 09:41 PM PST I have a working app. using Ruby on Rails where users could communicate and exchange pictures. I would like that users could have the options to evaluate the pictures.For ex, if the picture of some flowers provided, then the users could vote which flower is the most attractive. And those votes would be displayed as for ex. the flower #5 -got 30 votes and it is winner.... How to achieve it? Is the any examples that I could follow and use or at least where could I find direction to follow to solve this task? thanks. |
Rails Includes with ordering not by ID Posted: 25 Dec 2016 10:57 PM PST I have a simple include statement in my controller but the order for the included table is by default id. In my case I need to order the element in the same way as the uuid is received. Query: compare_uuids = {xyz, ytb, tyd} @books = Book.where(uuid: compare_uuids).includes(:venue, :related_publisher, :related_author) The above expression is responding well but say if the uuid ordering with their id are as: id uuid 5 xyz 1 ytb 2 tyd The expressions that make up when the statement run is order by id. So the uuid order is lost. Is there any work around to it. |
How to switch between subdomain and namespace dynamically in rails routes Posted: 25 Dec 2016 09:33 PM PST I would like to create a dynamic routes, like this https://subdomain.mysite.me/admin https://mysite.me/subdomain/admin I can set my routes for subdomain constraints, or namespace , but I don't know how to make them both are available. |
Mailboxer validation Posted: 25 Dec 2016 08:39 PM PST Hi where can I edit the mailboxer gem message validation settings? For example I'd like to restrict certain types of messages to be a certain length. Is there any way I can edit the inner models of the gem? |
I am working on An Ruby on Rails app Posted: 25 Dec 2016 10:46 PM PST I am working an an Rails app. The problem I am have is when I cycle between my about and contact pages. I always get the error No route matches [GET] "/pages/pages/about" or No route matches [GET] "/pages/pages/contact" I'm trying to change the routes my nav bar partial the tag href to "/about" but the same error occur. it ask me to use the command rake routes and it shows $ rake routes restaurants GET /restaurants(.:format) restaurants#index POST /restaurants(.:format) restaurants#create new_restaurant GET /restaurants/new(.:format) restaurants#new edit_restaurant GET /restaurants/:id/edit(.:format) restaurants#edit restaurant GET /restaurants/:id(.:format) restaurants#show PUT /restaurants/:id(.:format) restaurants#update DELETE /restaurants/:id(.:format) restaurants#destroy pages_about GET /pages/about(.:format) pages#about root / restaurants#index pages_contact GET /pages/contact(.:format) pages#contact" can some one please help me!! |
Custom optional parameter in Rails server command Posted: 25 Dec 2016 11:29 PM PST I want to use custom optional parameters in Rails server command like this or with some variants regarding the format of the optional parameters: rails s --foo bar Probably I would be using the optparse gem. How can I set something like this? |
Ruby on rails, Save data in two tables Posted: 25 Dec 2016 10:50 PM PST I have a question. I have this model: class Project < ApplicationRecord has_many :documents belongs_to :course_unit belongs_to :user has_and_belongs_to_many :people has_one :presentation has_and_belongs_to_many :supervisors, :class_name => "Person", :join_table => :projects_supervisors end and this model: class Presentation < ApplicationRecord belongs_to :project has_and_belongs_to_many :juries, :class_name => "Person", :join_table => :juries_presentations end When I create a new project, I have many attributes of the model Project and two attributes (room and date) from Presentation model, so I don't know how to send data from room and date attributes to the presentation model. So my question is: How can I create a new project that saves data in project table and presentation table? UPDATE #1 My project controller: def new @project = Project.new end def edit end def create @project = Project.new(project_params) @project.build_presentation respond_to do |format| if @project.save format.html { redirect_to @project, notice: 'Project was successfully created.' } format.json { render :show, status: :created, location: @project } else format.html { render :new } format.json { render json: @project.errors, status: :unprocessable_entity } end end end def update respond_to do |format| if @project.update(project_params) format.html { redirect_to @project, notice: 'Project was successfully updated.'} format.json { render :show, status: :ok, location: @project } else format.html { render :edit } format.json { render json: @project.errors, status: :unprocessable_entity } end end end private def set_project @project = Project.find(params[:id]) end def project_params params.require(:project).permit(:title, :resume, :github, :grade, :project_url, :date, :featured, :finished, :user_id, :course_unit_id, presentation_attributes: [ :date , :room ]) end My index view for Projects is: <%= form_for @project do |f| %> <%= f.fields_for :presentations do |ff| %> <%= ff.label :"Dia de Apresentação" %> <%= ff.date_field :date %> <%= ff.label :"Sala de Apresentação" %> <%= ff.text_area :room %> <% end <%= f.submit %> <% end %> |
No comments:
Post a Comment