Rails 5 - form not updating Posted: 15 Oct 2016 08:05 AM PDT In my rails 5 app, I have a form (below) that is loading correctly, yet not updating. No notification of errors (should pass all validations (only on presence = true)). Error param is missing or the value is empty: tag pointing to the tag_params method. All help, suggestions, improvement, simplification welcome! Controller def update tagable = detect_tagable @tag = tagable.tags.find(params[:id]) @tag.update(tag_params) render '_tag_update' end def tag_params params.require(:tag).permit(:content, :location, :tagtype_id, annotation_attributes: { annotation_ids:[] }, document_attributes: { document_ids:[] }) end Routes Rails.application.routes.draw do root 'dashboard#index' devise_for :users resources :users, :documenttypes, :tagtypes, :business_partners resources :documents do resources :comments, :tags get "pdf", on: :member end resources :annotations do resources :comments, :tags get "pdf", on: :member end get "annotations/:id/annotate" => "annotations#annotate", as: 'annotate' Form: <%= simple_form_for [@tag.tagable, @tag], html: { class: 'form-horizontal', multipart: true }, wrapper: :horizontal_form, wrapper_mappings: { check_boxes: :horizontal_radio_and_checkboxes, radio_buttons: :horizontal_radio_and_checkboxes, boolean: :horizontal_boolean } do |f| %> <%= f.error_notification %> <%= f.input :content, placeholder: 'Tagged content'%> <%= f.association :tagtype, prompt: 'Select tag type', :collection => Tagtype.active.order(:name).where(:documenttype => @tag.tagable.documenttype_id) %> <%= f.input :location, prompt: 'add as x1, y1, x2, y2' %> <%= f.button :submit %> <% end -%> Rails server returns this (appears to be executed) Started PATCH "/annotations/6/tags/46" for ::1 at 2016-10-15 16:15:09 +0200 Processing by TagsController#update as HTML Parameters: {"authenticity_token"=>"7JMnYxy00zQXLIEfETSGWcMxPQFwNMYRJRyCeL9RMAQYtLygrf3UjamlZQdR/ajgTY2wH6DKOTeLE6yAUqbc6w==", "annotation_id"=>"6", "id"=>"46"} User Load (1.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 6], ["LIMIT", 1]] Annotation Load (1.1ms) SELECT "annotations".* FROM "annotations" WHERE "annotations"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]] Tag Load (1.0ms) SELECT "tags".* FROM "tags" WHERE "tags"."tagable_id" = $1 AND "tags"."tagable_type" = $2 AND "tags"."id" = $3 LIMIT $4 [["tagable_id", 6], ["tagable_type", "Annotation"], ["id", 46], ["LIMIT", 1]] (0.2ms) BEGIN Tagtype Load (0.5ms) SELECT "tagtypes".* FROM "tagtypes" WHERE "tagtypes"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]] (0.2ms) COMMIT Rendering tags/_tag_update.html.erb within layouts/application Annotation Load (0.4ms) SELECT "annotations".* FROM "annotations" WHERE "annotations"."id" = $1 LIMIT $2 [["id", 6], ["LIMIT", 1]] Tagtype Load (1.0ms) SELECT "tagtypes".* FROM "tagtypes" WHERE "tagtypes"."active" = $1 AND "tagtypes"."documenttype_id" = 2 ORDER BY "tagtypes"."name" ASC [["active", true]] Rendered tags/_tag_update.html.erb within layouts/application (43.0ms) Rendered shared/_menu.html.erb (2.9ms) Completed 200 OK in 220ms (Views: 203.3ms | ActiveRecord: 6.1ms) |
Need to secure my API keys in react Using 'dotenv' but I am getting an error `cannot resolve module 'fs'` Posted: 15 Oct 2016 06:45 AM PDT This is my main.js. ERROR in ./~/dotenv/lib/main.js Module not found: Error: Cannot resolve module 'fs' I want to protect my .env variables. When I run this code in node it works but on the app itself it fails out. I am new to coding and currently in a bootcamp...please be gentle...haha. import 'babel-polyfill'; import React from 'react'; import ReactDOM from 'react-dom'; import Ticket from './components/Ticket'; let dotenv = require('dotenv'); let ticketMasterKey = process.env.TICKETMASTER_KEY; $(function() { ReactDOM.render( <Ticket />, document.getElementById('app') ); }); |
How do I create an app that goes through the tor network? Posted: 15 Oct 2016 06:44 AM PDT I want to create an app which uses the tor network and anonymizes the user and all that he does in the app. I heard about stem among others. Also can I use it in a web app developed using ruby on rails. ps. I'm new to programming so please do explain it in great detail if you don't mind:D |
YAML.load_file issue Posted: 15 Oct 2016 06:50 AM PDT I have a bestiary.yml and test.rb in one directory, and when I try loading my .yml file like that got_data_1 = YAML.load_file('bestiary.yml') it gives me a /usr/lib/ruby/2.3.0/psych.rb:471:in `initialize': No such file or directory @ rb_sysopen error. But when I try launching this got_data = YAML.load(File.open(File.join(File.dirname(__FILE__), 'bestiary.yml'))) everything works fine. Why load_file method doesn't work and what's the difference between this two methods? Thank you |
Rails: Heroku and CloudFront CORS error Posted: 15 Oct 2016 06:21 AM PDT I have built a Rails 5 application, and uploaded to Heroku. I haven't set up a custom domain for my application yet, so I am using the heroku's default. As an example, lets use "custom.herokuapp.com". I've created a CloudFront on Amazon, with the domain custom.herokuapp.com. Then I changed the production.rb to add config.action_controller.asset_host = 'here-my-cloudfront.cloudfront.net' And then I pushed the changes to heroku. Almost all the assets worked, except of the fonts. I am not sure why, but this is the error I get in the browser's console: Font from origin 'https://here-my-cloudfront.cloudfront.net' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://custom.herokuapp.com' is therefore not allowed access Any ideas? |
uninitialized constant ApplicationRecord caused by factory girl? Posted: 15 Oct 2016 05:57 AM PDT I get uninitialized constant ApplicationRecord whenever I try to run rails db:migrate and the backtrace seems to be pointing to a spec of factory_girl . The exact line that causes the error is factory :test_user, class: User do Why is that happening? How is that ApplicationRecord isn't defined when that spec is parsed? How can I fix it? |
DEPRECATION WARNING after updating from Rails 5.0.0 to 5.0.0.1 Posted: 15 Oct 2016 05:47 AM PDT I updated my Rails app from 5.0.0 to 5.0.0.1 by running the command bundle update rails Some commands that gives me this warning are: rails s rails db:migrate rails db:seed git push heroku The full warning are: DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. Please register a mime type using `register_mime_type` then use `register_compressor` or `register_transformer`. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (called from block (2 levels) in <class:Railtie> at /home/jeramae/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sass-rails-5.0.5/lib/sass/rails/railtie.rb:57) DEPRECATION WARNING: Sprockets method `register_engine` is deprecated. Please register a mime type using `register_mime_type` then use `register_compressor` or `register_transformer`. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (called from block (2 levels) in <class:Railtie> at /home/jeramae/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/sass-rails-5.0.5/lib/sass/rails/railtie.rb:58) |
Improving ruby code Posted: 15 Oct 2016 07:02 AM PDT people said to me that I have an wrong code at this point. The main idea of this method is to create 1 event if user pressed once, and a row of events if user pressed daily or weekly. Everything works well, but code is so bulky. def create @event = Event.new(event_params @event.start_time = DateTime.parse(params[:start_time], "%Y-%m-%d %H:%i") @event.end_time = DateTime.parse(params[:end_time], "%Y-%m-%d %H:%i") @event.user_id = current_user.id @event.update_attributes(:repeat_id => @event.id) if @event.save respond_to do |format| if @event.save format.html { redirect_to persons_profile_path } else format.html { render :new } format.json { render json: @event.errors, status: :unprocessable_entity } end interval = 60 if @event.repeat =='daily' interval = 20 if @event.repeat =='weekly' #creating row of events if @event.repeat != 'once' (1..interval).each do |i| @event = Event.new(event_params) @event.start_time = DateTime.parse(params[:start_time], "%Y-%m-%d %H:%i") @event.end_time = DateTime.parse(params[:end_time], "%Y-%m-%d %H:%i") @event.user_id = current_user.id if @event.repeat =='daily' @event.start_time = DateTime.parse(@event.start_time.to_s) + i.day @event.end_time = DateTime.parse(@event.end_time.to_s) + i.day end if @event.repeat =='weekly' @event.start_time = DateTime.parse(@event.start_time.to_s) + i.week @event.end_time = DateTime.parse(@event.end_time.to_s) + i.week end @event.update_attributes(:repeat_id => k) if @event.save @event.save end end I can't find another solutions. Any ideas? Dont pay attention on parse methods on date, its needed to JS. |
How to convert XML to Hash in ruby? Posted: 15 Oct 2016 07:47 AM PDT I have a XML code which I want to convert into Hash <meta_description><language id="1"></language><language id="2"></language></meta_description> <meta_keywords><language id="1"></language><language id="2"></language></meta_keywords> <meta_title><language id="1"></language><language id="2" ></language></meta_title> <link_rewrite><language id="1" >konsult-500-krtim</language><language id="2" >konsult-500-krtim</language></link_rewrite> <name><language id="1" >Konsult 500 kr/tim</language><language id="2" >Konsult 500 kr/tim</language></name> <description><language id="1" ></language><language id="2" ></language></description> <description_short><language id="1" ></language><language id="2" ></language></description_short> <available_now><language id="1" ></language><language id="2" ></language></available_now> <available_later><language id="1" ></language><language id="2" ></language></available_later> <associations> <categories nodeType="category" api="categories"> <category> <id>2</id> </category> </categories> <images nodeType="image" api="images"/> <combinations nodeType="combination" api="combinations"/> <product_option_values nodeType="product_option_value" api="product_option_values"/> <product_features nodeType="product_feature" api="product_features"/> <tags nodeType="tag" api="tags"/> <stock_availables nodeType="stock_available" api="stock_availables"> <stock_available> <id>111</id> <id_product_attribute>0</id_product_attribute> </stock_available> </stock_availables> <accessories nodeType="product" api="products"/> <product_bundle nodeType="product" api="products"/> </associations> I want to convert this xml into Hash . I try to find functions which convert this xml to h=Hash.new How I do this? |
ActiveRecord::Base.transaction validation missing Posted: 15 Oct 2016 05:13 AM PDT Rails 4.1.16 or 4.2.7 Lets, for example, we have class Foo < ActiveRecord::Base validate :name, presence: true end Then in IRB we will get Foo.create # => validation error Foo.transaction{ Foo.create } # COMMIT I can figure out, that there is no raise in transaction block, it mean, that it will be committed (on course I can use create! , but it does not cancel the question). But validation fails! IMHO this behaviour is not less than strange. Can you clarify, why it was made in this way? May be I'm do not understood some specific in this case? It will be perfect, if you know how to make ActiveRecord failing loudly, with no sense of !(bang) at the and of the command. Thank you! |
ActiveModel::Serializer::Adapter.create(serializer_object, include: '*,user.**').to_json Posted: 15 Oct 2016 04:18 AM PDT ActiveModel::Serializer::Adapter.create(serializer_object, include: '*,user.**').to_json I understand the code but not getting the meaning of '*,user.'** . Can any one explain this '*,user.'** ? Question 2 I want to add references in the include, How can I do that? |
Selecting all the records from table to which given number belongs to Posted: 15 Oct 2016 03:52 AM PDT Suppose I have following three records in my model : #<Rda:0xf6e8a0c id: 1, age_group: "18-100", weight: "60", nutrient: "energy(kcal/day)", value: "2730", created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00, updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00> #<Rda:0xf6e8a0c id: 2, age_group: "10-15", weight: "60", nutrient: "energy(kcal/day)", value: "2730", created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00, updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00> #<Rda:0xf6e8a0c id: 3, age_group: "20-100", weight: "60", nutrient: "energy(kcal/day)", value: "2730", created_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00, updated_at: Sat, 15 Oct 2016 08:21:43 UTC +00:00> Now, I want to get all those records in which my given value falls in a 'age_group' columns ranges. For example: suppose my age is 25 then I should get records with ids 1 & 3 from the above records because '25' falls in between '18-100' and '20-100' |
Rails 5: edit action on dropdown change Posted: 15 Oct 2016 04:39 AM PDT In roles view I have drop-down where users can be selected (user_id is placed in roles table) for particular user role edit. /views/common/roles/edit.html.erb looks like this: <div class="form-group"> <%= form_for [:common, @role] do |f| %> <label class="col-sm-2 control-label">User name</label> <div class="col-sm-10"><select class="form-control m-b" name="user_list"> <option value=<%= f.collection_select :user_id, @users, :id, :name %></option> </select> </div> How to make on change action edit_common_roles_path open for selected user role? Thank you for any help! |
Find first five users with highest points Posted: 15 Oct 2016 03:43 AM PDT I have an Invitee model which belongs_to :event and has_many :analytics with a column points in which all points are stored Event model which has_many :invitees and has_many :analytics Analytic model which belongs_to :event In analytic model I've defined some action_points like for comment he will get 2 points for rating 5 points ACTION_POINTS = {"favorite" => 5, "rated" => 5, "comment" => 2, "conversation post" => 5, "like" => 2} I want to get those first five invitees who get 1000 points first - for this what I've done so far is In my invitee model I created a method on after update and also added a time field invitee_points_time after_update :update_time, if: -> { points == 1000} scope :thousand_points, -> { where(points: '1000').order('invitee_points_time DESC') } def update_time self.update_column('invitee_points_time', Time.now) end and then I was thinking of getting those five invitees with highest times. But the problem is arising on existing invitees which already have points more then 1000 and I also want to get list of those five invitees with points who got 1000 points first. And yes It should be like from events e.g Event.last.invitee.analytics Please tell me if I forget to mention something. To get the list of old invitees with points I did this Analytic.select("invitee_id, sum(points) as sum_points").where(:invitee_id => Event.find(364).invitees.pluck(:id)).group(:invitee_id).having("sum_points > 1000").map{|a| [a.invitee_id, a.sum_points]} This is what I got [[8358, 1929], [11326, 1340], [11328, 1200], [11358, 1042], [11366, 2699], [11377, 11737], [11415, 7968], [11421, 1398], [11429, 1965], [11437, 1750], [11443, 54928], [11447, 3052], [11448, 28045], [11449, 2846], [11455, 3436], [11457, 40937], [11458, 32163], [11460, 2179], [11935, 2784]] But I don't really understand how to find out from them(old records) and from new records which 5 invitees reaches to first 1000 points. |
Ruby on Rails mysql2 connection last_id always returns 0 Posted: 15 Oct 2016 03:06 AM PDT I'm using Rails 5, mysql 5.7 and I need to get the last id of the previous insert statement(which inserts multiple records using load data infile command), and I don't want to just use Model.last.id as it may happen that another process has inserted new records just before the first process asks for the last_id, so I tried using ActiveRecord::Base.connection.raw_connection.last_id , as uses a mysql call that works per connection, however this method always returns 0, although new records are inserted and the primary key is auto incremented. So any clue ? |
What should be the database schema for my requirement? Posted: 15 Oct 2016 03:58 AM PDT I want to create "Conference Room Booking" Application in rails. Requirements: Manager should be able to add one or more conference rooms. User should be able to book rooms for a particular conference room for a particular time-slot for a particular day User should not be able to book a room already booked by another user for a particular time-slot, but there should be a wait queue in-case of a cancellation. User should be able to mark certain days as holidays Rooms cannot be booked on a holiday or a weekend User should be able to see the room bookings and see the name of the person who booked the room and Time-slot for each booking Manger should be able to add various facilities to a room and rooms should be searchable on the basis of these facilities These are my Application Requirements. I am not sure How many models to be created, And what associations needs to be established, and how many column are needed in each table And what should be the datatypes of the columns? as per my knowledge there are three models required they are Manager ,User And Room. but iam having problem in establishing the associations and creating the columns with appropriate datatypes in each moldel. |
Rails AssociationTypeMismatch Posted: 15 Oct 2016 05:59 AM PDT I have form's field and want to use with select2 <%= f.collection_select :product_ids, Product.all,:id, :name ,{},{ class: 'p_ids', multiple: true} %> my js $(document).ready(function () { $(".p_ids").select2({ tags:true, tokenSeparators: [",", " "] }); }); my params params.require(:cost).permit(:day, :amount, :description, :source, product_ids:[]) but i have got Product(#70204276011560) expected, got NilClass(#70204185305100) log "cost"=>{"day"=>"15-10-2016", "amount"=>"100", "description"=>"test", "source"=>"products", "product_ids"=>["", "1", "2"]} How to fix it? |
Rails Seeding many 2 many table issues Posted: 15 Oct 2016 06:20 AM PDT I am new to Rails and having an issue seeding a many 2 many relationship table. Here is the ERD I can successfully create users and projects with this: user1 = User.create!({ name: "Mike Rubin", userid: "merubin", password: "password", email:"mike@rubinsworld.com", avatar_url:"http://mike-rubin.com/images/nav/id/rubin_selfie_270.png" }) project1 = user1.projects.create!({ name:"Mario's Match Game", header1:"Javascript Project", header2:"", description:"Pre-work project for WDI-DC12 Bootcamp. Concentration like game where random cards are displayed and flipped as user choices. This work includes CSS, HTML5 along with Javascript and dynamic DOM manulipuation. Bonus work to keep score and win and loss was done.", screen_img_url:"http://mike-rubin.com/images/portfolio/mariomemorygame.jpg", host_url:"http://www.rubinsworld.com/ga/memory/index.html" }) If I try to create a portfolio with this: portfolio1 = project1.portfolios.create!({ title:"Mike Rubin's Personal Portfolio", description:"Welcome to Mike Rubin's Web Development Portfolio. " }) I get this error: $ rails db:seed rails aborted! ActiveRecord::RecordInvalid: Validation failed: User must exist Do I need to somehow create the ProjectsPortfio record first and seed the userid? if so how? schema and seeds located here on github Thanks, Mike |
got this bug in ruby/rails Posted: 15 Oct 2016 02:23 AM PDT Got this error in rails 5.0.0.1 in ruby 2.3.1 while creating a post with title. I have already submitted the full error in ruby bug reporter site. Getting this problem frequently.I tried formatting sierra and then installing it again. Still getting this error. Nischals-Device:jwt_api_auth nischalgautam$ rails c Running via Spring preloader in process 23900 Loading development environment (Rails 5.0.0.1) 2.3.1 :001 > @post=Post.create(title: "hello") /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27: [BUG] Segmentation fault at 0x00000000000110 ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16] -- Crash Report log information -------------------------------------------- See Crash Report log file under the one of following: * ~/Library/Logs/CrashReporter * /Library/Logs/CrashReporter * ~/Library/Logs/DiagnosticReports * /Library/Logs/DiagnosticReports for more details. Don't forget to include the above Crash Report log file in bug reports. -- Control frame information ----------------------------------------------- c:0063 p:---- s:0262 e:000261 CFUNC :initialize c:0062 p:---- s:0260 e:000259 CFUNC :new c:0061 p:0183 s:0255 e:000254 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27 c:0060 p:0028 s:0248 e:000247 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0059 p:0027 s:0245 e:000244 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0058 p:0025 s:0242 e:000241 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0057 p:0018 s:0237 e:000236 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0056 p:0016 s:0232 e:000230 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0055 p:0035 s:0227 e:000223 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0054 p:0046 s:0221 e:000220 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_p c:0053 p:0015 s:0215 e:000214 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:128 c:0052 p:0008 s:0212 e:000211 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:91 c:0051 p:0008 s:0209 e:000208 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:354 c:0050 p:0010 s:0206 e:000205 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attributes.rb:233 c:0049 p:0010 s:0203 e:000202 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attribute_decorators.rb:28 c:0048 p:0019 s:0200 e:000199 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:349 c:0047 p:0008 s:0197 e:000196 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:266 c:0046 p:0008 s:0194 e:000193 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods.rb:179 c:0045 p:0062 s:0190 e:000189 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:54 c:0044 p:0042 s:0183 e:000182 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:33 c:0043 p:0014 s:0177 e:000176 EVAL (irb):1 [FINISH] c:0042 p:---- s:0175 e:000174 CFUNC :eval c:0041 p:0025 s:0168 e:000167 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87 c:0040 p:0027 s:0161 e:000159 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/context.rb:380 c:0039 p:0024 s:0155 e:000154 BLOCK /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:489 c:0038 p:0041 s:0147 e:000146 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:623 c:0037 p:0011 s:0142 e:000141 BLOCK /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:486 c:0036 p:0128 s:0138 e:000137 BLOCK /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:246 [FINISH] c:0035 p:---- s:0135 e:000134 CFUNC :loop c:0034 p:0009 s:0132 e:000131 BLOCK /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:232 [FINISH] c:0033 p:---- s:0130 e:000129 CFUNC :catch c:0032 p:0018 s:0126 e:000125 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:231 c:0031 p:0037 s:0123 E:001c40 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:485 c:0030 p:0009 s:0120 e:000119 BLOCK /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:395 [FINISH] c:0029 p:---- s:0118 e:000117 CFUNC :catch c:0028 p:0174 s:0114 E:0004f0 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:394 c:0027 p:0160 s:0109 E:001c20 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65 c:0026 p:0015 s:0106 E:000538 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9 c:0025 p:0101 s:0102 E:000588 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78 c:0024 p:0036 s:0098 E:0005d8 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49 c:0023 p:0127 s:0094 E:000630 TOP /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18 [FINISH] c:0022 p:---- s:0090 e:000089 CFUNC :require c:0021 p:0012 s:0086 E:0006c0 BLOCK /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293 c:0020 p:0057 s:0084 E:000740 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259 c:0019 p:0017 s:0079 E:000680 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293 c:0018 p:0063 s:0074 E:000798 TOP /Users/nischalgautam/Desktop/lang/ruby/railsprojects/jwt_api_auth/bin/rails:9 [FINISH] c:0017 p:---- s:0071 e:000070 CFUNC :load c:0016 p:0014 s:0066 E:001680 BLOCK /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287 c:0015 p:0057 s:0064 E:001700 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259 c:0014 p:0021 s:0059 E:001638 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287 c:0013 p:0056 s:0053 E:001750 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/commands/rails.rb:6 c:0012 p:0024 s:0050 E:001790 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/command_wrapper.rb:38 c:0011 p:0204 s:0047 E:001860 BLOCK /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:191 [FINISH] c:0010 p:---- s:0045 e:000044 CFUNC :fork c:0009 p:0272 s:0042 E:001820 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161 c:0008 p:0075 s:0029 E:0018e0 BLOCK /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:131 [FINISH] c:0007 p:---- s:0027 e:000026 CFUNC :loop c:0006 p:0028 s:0024 E:0018a0 METHOD /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125 c:0005 p:0167 s:0021 E:0008e8 TOP /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application/boot.rb:19 [FINISH] c:0004 p:---- s:0018 e:000017 CFUNC :require c:0003 p:0124 s:0014 E:001988 METHOD /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55 c:0002 p:0008 s:0004 E:001be0 EVAL -e:1 [FINISH] c:0001 p:0000 s:0002 E:001cf0 (none) [FINISH] -- Ruby level backtrace information ---------------------------------------- -e:1:in `<main>' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `run' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `serve' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:161:in `fork' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/application.rb:191:in `block in serve' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/command_wrapper.rb:38:in `call' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/spring-2.0.0/lib/spring/commands/rails.rb:6:in `call' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load' /Users/nischalgautam/Desktop/lang/ruby/railsprojects/jwt_api_auth/bin/rails:9:in `<top (required)>' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:394:in `start' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:394:in `catch' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:395:in `block in start' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:485:in `eval_input' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:486:in `block in eval_input' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:623:in `signal_status' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:489:in `block (2 levels) in eval_input' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/context.rb:380:in `evaluate' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87:in `evaluate' /Users/nischalgautam/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87:in `eval' (irb):1:in `irb_binding' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:33:in `create' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/inheritance.rb:54:in `new' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods.rb:179:in `has_attribute?' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:266:in `attribute_types' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:349:in `load_schema' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attribute_decorators.rb:28:in `load_schema!' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attributes.rb:233:in `load_schema!' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:354:in `load_schema!' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:91:in `connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:128:in `retrieve_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:875:in `retrieve_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:501:in `checkout' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:705:in `acquire_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:744:in `try_to_checkout_new_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:765:in `checkout_new_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `sqlite3_connection' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `new' /Users/nischalgautam/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:27:in `initialize' -- Machine register context ------------------------------------------------ rax: 0x0000000000000100 rbx: 0x00007fffc376b430 rcx: 0x0000000000000000 rdx: 0x0000000000000000 rdi: 0x00007fffc37ce1c0 rsi: 0x00007f9064f97e40 rbp: 0x00007fff5d4be0d0 rsp: 0x00007fff5d4be088 r8: 0x00000000a40008ff r9: 0x00000000ffffffff r10: 0x0000000100000000 r11: 0x0000000000000000 r12: 0x00007fffc37696d0 r13: 0x0000000000000000 r14: 0x00007f9062664990 r15: 0x00007f9062664b58 rip: 0x00007fffbaae8943 rfl: 0x0000000000010206 -- C level backtrace information ------------------------------------------- 0 libruby.2.3.0.dylib 0x00000001028e8a44 rb_vm_bugreport + 388 1 libruby.2.3.0.dylib 0x0000000102783c8a rb_bug_context + 490 2 libruby.2.3.0.dylib 0x0000000102858a54 sigsegv + 68 3 libsystem_platform.dylib 0x00007fffbad15bba _sigtramp + 26 4 libdispatch.dylib 0x00007fffbaae8943 _dispatch_queue_push + 171 5 libsqlite3.dylib 0x00007fffba6b2d78 fillInUnixFile + 568 6 libsqlite3.dylib 0x00007fffba6b29b0 unixOpen + 2192 7 libsqlite3.dylib 0x00007fffba6ae7f8 sqlite3BtreeOpen + 2856 8 libsqlite3.dylib 0x00007fffba6aa761 openDatabase + 1169 9 sqlite3_native.bundle 0x00000001035bf802 initialize + 962 10 libruby.2.3.0.dylib 0x00000001028e5844 vm_call0_body + 532 11 libruby.2.3.0.dylib 0x00000001028e60dd rb_call0 + 397 12 libruby.2.3.0.dylib 0x00000001027e5a99 rb_class_new_instance + 41 13 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 14 libruby.2.3.0.dylib 0x00000001028c94ac vm_exec_core + 10220 15 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 16 libruby.2.3.0.dylib 0x00000001028e6d95 eval_string_with_cref + 1605 17 libruby.2.3.0.dylib 0x00000001028d53f1 rb_f_eval + 161 18 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 19 libruby.2.3.0.dylib 0x00000001028c94ac vm_exec_core + 10220 20 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 21 libruby.2.3.0.dylib 0x00000001028e7180 loop_i + 48 22 libruby.2.3.0.dylib 0x000000010278d358 rb_rescue2 + 280 23 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 24 libruby.2.3.0.dylib 0x00000001028c92b8 vm_exec_core + 9720 25 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 26 libruby.2.3.0.dylib 0x00000001028e7117 catch_i + 87 27 libruby.2.3.0.dylib 0x00000001028d65eb rb_catch_protect + 155 28 libruby.2.3.0.dylib 0x00000001028d6e4c rb_f_catch + 76 29 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 30 libruby.2.3.0.dylib 0x00000001028c92b8 vm_exec_core + 9720 31 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 32 libruby.2.3.0.dylib 0x00000001028e7117 catch_i + 87 33 libruby.2.3.0.dylib 0x00000001028d65eb rb_catch_protect + 155 34 libruby.2.3.0.dylib 0x00000001028d6e4c rb_f_catch + 76 35 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 36 libruby.2.3.0.dylib 0x00000001028c92b8 vm_exec_core + 9720 37 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 38 libruby.2.3.0.dylib 0x0000000102790430 rb_load_internal0 + 288 39 libruby.2.3.0.dylib 0x0000000102790cf5 rb_require_internal + 1829 40 libruby.2.3.0.dylib 0x00000001027904b8 rb_f_require + 24 41 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 42 libruby.2.3.0.dylib 0x00000001028c9715 vm_exec_core + 10837 43 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 44 libruby.2.3.0.dylib 0x0000000102790430 rb_load_internal0 + 288 45 libruby.2.3.0.dylib 0x000000010279129f rb_f_load + 159 46 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 47 libruby.2.3.0.dylib 0x00000001028c9715 vm_exec_core + 10837 48 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 49 libruby.2.3.0.dylib 0x00000001028d4bf7 rb_yield + 183 50 libruby.2.3.0.dylib 0x000000010278d59a rb_protect + 250 51 libruby.2.3.0.dylib 0x0000000102810e2d rb_f_fork + 93 52 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 53 libruby.2.3.0.dylib 0x00000001028c92b8 vm_exec_core + 9720 54 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 55 libruby.2.3.0.dylib 0x00000001028e7180 loop_i + 48 56 libruby.2.3.0.dylib 0x000000010278d358 rb_rescue2 + 280 57 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 58 libruby.2.3.0.dylib 0x00000001028c92b8 vm_exec_core + 9720 59 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 60 libruby.2.3.0.dylib 0x0000000102790430 rb_load_internal0 + 288 61 libruby.2.3.0.dylib 0x0000000102790cf5 rb_require_internal + 1829 62 libruby.2.3.0.dylib 0x00000001027904b8 rb_f_require + 24 63 libruby.2.3.0.dylib 0x00000001028ded4a vm_call_cfunc + 314 64 libruby.2.3.0.dylib 0x00000001028c94ac vm_exec_core + 10220 65 libruby.2.3.0.dylib 0x00000001028d9583 vm_exec + 131 66 libruby.2.3.0.dylib 0x000000010278c708 ruby_exec_internal + 152 67 libruby.2.3.0.dylib 0x000000010278c616 ruby_run_node + 54 68 ruby 0x000000010273bf2f main + 79 |
Searching through a seeded list on ruby on rails Posted: 15 Oct 2016 01:20 AM PDT I have a long list of seeded databases. I can select which ones I want. I want to able to search for the ones I want and pick them. How do I begin making a sort of search box where I can look for one, find it, select it and then look for another one and have the next one selected? |
Rails 5 - NoMethod Error - undefined method Posted: 15 Oct 2016 04:10 AM PDT In the app I am building to learn Rails, I have a polymorphic relationship between the model "TAG" and the models "ANNOTATION" and "DOCUMENT". Similar to Article and Comment models. Create and destroy of tags is working. Now, I want to update the tags and run into a no method error I don't understand. Tried many alternatives (e.g. using <%= link_to tag.content, [object, tag]... with the form <%= simple_form_for object.tag ... ). The form is called using: <% object.tags.each do |tag| %> <% unless tag.content.blank? %> <tr> <td><%= link_to tag.content, @tag, method: :patch %></td> This is the tags controller: class TagsController < ApplicationController def index end def create tagable = detect_tagable tagable.tags.create(tag_params) redirect_to tagable_path(tagable) end def update tagable = detect_tagable @tag = tagable.tags.find(params[:id]) @tag.save render '_tag_update' end def destroy tagable = detect_tagable @tag = tagable.tags.find(params[:id]) @tag.destroy redirect_to tagable_path(tagable) end private def tagable_path(tagable) case tagable when Document document_path(tagable) when Annotation annotate_path(tagable) else fail 'Unknown tagable' end end def detect_tagable if params[:annotation_id] Annotation.find(params[:annotation_id]) elsif params[:document_id] Document.find(params[:document_id]) else fail 'Tagable not found' end end def tag_params params.require(:tag).permit(:content, :location, :tagtype_id,annotation_attributes: { annotation_ids:[] }, document_attributes: { document_ids:[] }) end end It renders the correct form _tag_update.html.erb with the right parameters (annotation id and tag id) yet throws the error on: <%= simple_form_for @tag, html: { class: 'form-vertical', multipart: true }, Full error NoMethodError in Tags#update Showing /Users/Dimitri/Documents/AppDev/shine/app/views/tags/_tag_update.html.erb where line #1 raised: undefined method `tag_path' for #<#:0x007fc2aede9d88> Did you mean? tagtype_path Extracted source (around line #1): 1 2 3 4 5 6 <%= simple_form_for @tag, html: { class: 'form-vertical', multipart: true }, wrapper: :horizontal_form, wrapper_mappings: { check_boxes: :horizontal_radio_and_checkboxes, radio_buttons: :horizontal_radio_and_checkboxes, file: :horizontal_file_input, Rails.root: /Users/Dimitri/Documents/AppDev/shine Application Trace | Framework Trace | Full Trace: app/views/tags/_tag_update.html.erb:1:in _app_views_tags__tag_update_html_erb___1949489846228898836_70237067101380' app/controllers/tags_controller.rb:17:in update' Request Parameters: {"_method"=>"patch", "authenticity_token"=>"LhqKjyjbYdznMvx+GjsIL0phwT8pRTtanooKU6Xt4hHaPRFMmZJmZVm7GGZa8iaWxN1MIfm7xHwwhSSrSBoO/g==", "annotation_id"=>"6", "id"=>"24"} |
Rails 5, Rolify - Role Assignment Strategy Posted: 15 Oct 2016 01:14 AM PDT I am not very good at learning how to code. I've been trying for 4 years and still struggling to figure out basic concepts. I haven't found the right starting point so, I'm constantly gap filling for things that might be foundations and I don't know them yet. I have a Rails 5 app. It has models for user, roles, app_roles and assign_roles. The associations are: User rolify strict: true # strict means you get true only on a role that you manually add attr_accessor :current_role Role has_and_belongs_to_many :users, :join_table => :users_roles belongs_to :resource, :polymorphic => true, :optional => true AppRole [no associations] Note: this is the resource I'm using to have a CRUD to define roles that the app can use to assign roles to users. Assign Role [no associations] Note: this is the resource I'm using to allow some users to assign roles to some other users. I'm using rolify gem. In my assign_roles controller, index action, I have: class Users::AssignRolesController < ApplicationController before_action :authenticate_user! def index @app_roles = AppRole.all @users = User.all end In my routes file, i have: resources :users, shallow: true do scope module: :users do resources :assign_roles resources :identities end end In my views/users/assign_roles/index file, I have: <%= form_tag(url: '/assign_roles', method: :post ) do |f| %> <div class="row" style="margin-top:50px; margin-bottom: 150px"> <div class="col-md-3 col-md-offset-1"> <%= select_tag "users", options_from_collection_for_select(@users, "id", "full_name"), { class: "chosen-select form-control" } %> </div> <!-- # roles --> <div class="col-md-3 col-md-offset-1"> <%= select_tag "roles", options_from_collection_for_select(@app_roles, "id", "display_name"), :class => 'chosen-select form-control' %> </div> <div class="col-md-3 col-md-offset-1"> <div class="form-actions"> <%= submit_tag(value = "Submit") %> </div> </div> </div> <% end %> So far, that all looks OK. Im' getting stuck at the next part. In my views/users/assign_roles/show.html.er I'm trying to show each user's roles on a view. I want the user that assigned any existing roles to be able to delete them. I have: <% @users.each do |user| %> <td><%= user.roles.count %></td> <% user.roles.each do |role| %> <td><%= role.name.titleize %></td> <td><%= link_to 'Destroy', role, method: :delete, data: { confirm: 'Are you sure?' } %></td> <% end %> <% end %> My controller for assign_roles is saved in app/controllers/users folder. My views folder for assign roles is saved inside app/views/users/assign_roles The index render works fine. I can't figure out what needs to happen for me to be able to render the show page. When I rake routes | rep assign, I get: user_assign_roles GET /users/:user_id/assign_roles(.:format) users/assign_roles#index POST /users/:user_id/assign_roles(.:format) users/assign_roles#create new_user_assign_role GET /users/:user_id/assign_roles/new(.:format) users/assign_roles#new edit_assign_role GET /assign_roles/:id/edit(.:format) users/assign_roles#edit assign_role GET /assign_roles/:id(.:format) users/assign_roles#show PATCH /assign_roles/:id(.:format) users/assign_roles#update PUT /assign_roles/:id(.:format) users/assign_roles#update DELETE /assign_roles/:id(.:format) users/assign_roles#destroy so, given the step I'm trying to take is #show, I need: assign_role GET /assign_roles/:id(.:format) users/assign_roles#show When I try: http://localhost:3000/users/1/assign_roles/show I get: No route matches [GET] "/users/1/assign_roles/show" It looks to me from the rake routes that I need to move the '1' out of the url, but when I try: http://localhost:3000/users/assign_roles/show I get: No route matches [GET] "/users/assign_roles/show" (this approach doesnt actually make any sense to me anyway, given I need to know which user im enquiring about in order to see which list of roles I want to manage). I don't understand any of this, so Im lost for how to go about searching for solutions. Please can you help me with the name of the concept I need to research. I've read about nested routes and namespaces routes and accepts nested attributes for forms - but I don't think any of these issues is my solution (at lease if they are, I can't find the jargon-free version of the explanation as to why). |
How to save id for both nested attributes? Posted: 15 Oct 2016 01:59 AM PDT This is what I currently get: Started POST "/duels" for 127.0.0.1 at 2016-10-15 02:51:06 -0400 Processing by DuelsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"/vNueb1U+W5asQ4/Vnh5kSdeUc6uiaUKvWG1TIaAKWY0fIM2ovLlsLJUSsmgDG3nTbFgt7n8zSYYT2LkZEqLrA==", "duel"=>{"duelers_attributes"=>{"0"=>{"user_id"=>"2"}, "1"=>{"user_id"=>"15"}}, "consequence"=>"t", "reward"=>"t"}, "dueler"=>{"challenge_id"=>"141"}, "button"=>""} Only one challenge_id is passing through although there should be two (one for each dueler). How can I get the below code to output something like this upon submit: Started POST "/duels" for 127.0.0.1 at 2016-10-15 03:33:02 -0400 Processing by DuelsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"xhbQpHgBmzfuvmYsyZx1Hss8CZBfQQN9+QCEciiq4yUMmT3rZ6eH6QZbIto/6GFoodM46Ug0a1FcLlPaymBB7w==", "duel"=>{"duelers_attributes"=>{"0"=>{"user_id"=>"2", "challenge_id"=>"141"}, "1"=>{"user_id"=>"15", "challenge_id"=>"143"}}, "consequence"=>"t", "reward"=>"t"}, "button"=>""} duels_controller def new @duel = Duel.new @user = User.find(params[:challenge_daddy]) @duel.duelers << Dueler.new(user_id: current_user.id, user_name: current_user.name, user_last_name: current_user.last_name) @duel.duelers << Dueler.new(user_id: @user.id, user_name: @user.name, user_last_name: @user.last_name) @current_user_challenges = current_user.challenges.order(:created_at) @challenged_user_challenges = @user.challenges.order(:created_at) respond_with(@duel) end duels/new <%= simple_form_for(@duel) do |f| %> <%= f.fields_for(:duelers) do |dueler| %> <%= render 'dueler_fields', :f => dueler %> <% end %> The loser will <%= f.text_field :consequence %> <%= f.submit %> <% end %> _dueler_fields.html.erb <%= f.select :user_id, User.order(:name).map { |user| [user.full_name, user.id] }, include_blank: true, id: "change-challenge-options" %> <div id="current-user-challenges"> <%= f.collection_select :challenge_id, @current_user_challenges, :id, :full_challenge, include_blank: true %> </div> <div id="challenged-user-challenges"> <%= f.collection_select :challenge_id, @challenged_user_challenges, :id, :full_challenge, include_blank: true %> </div> <script> # If current_user then I show first collection_select otherwise I show second. var userSelect = $('#change-challenge-options'); var currentUserId = $('#current-user-id').data('user-id'); $('#challenged-user-challenges').hide(); $('#current-user-challenges').hide(); userSelect.on('change', function() { if (userSelect.val() == "0"){ $('#current-user-challenges').hide(); $('#challenged-user-challenges').hide(); } else if (userSelect.val() == currentUserId) { $('#current-user-challenges').show(); $('#challenged-user-challenges').hide(); } else { $('#challenged-user-challenges').show(); $('#current-user-challenges').hide(); } }); </script> |
Limiting Multitenant Application Account By Number Of Users Posted: 15 Oct 2016 05:55 AM PDT So I am building out an application using Rails 4 and the Apartment Gem. I am fairly new to multitenancy and have come to the point where I am building out user plans. I have 4 main plans and I want each plan to limit the number of users that can be created, before telling the account owner or admin that they need to upgrade to register new users. I think I am more stuck on where this should be done.. In my account model I have my constant for Plan: PLAN = %w[responder first_responder patrol_pro guardian] each of these plan_types (column I am saving to on sign up) have a set number of users that can be created, these are also set as constants below: RESPONDER_PLAN_USER_LIMIT = 6 FIRST_RESPONDER_PLAN_USER_LIMIT = 12 PATROL_PRO_PLAN_USER_LIMIT = 30 GUARDIAN_PLAN_USER_LIMIT = 60 I have also created the below methods to verify the plan type however this seems clunky and was wondering if there was a way i could do this in one method instead of 4 def responder_plan? self.plan_type == 'responder' end def first_responder_plan? self.plan_type == 'first_responder' end def patrol_pro_plan? self.plan_type == 'patrol_pro' end def guardian_plan? self.plan_type == 'guardian' end Now for the last issue, to actually count the users attached to the account I was planning on using a Validator to do so, i am just un-sure of how to create the model method. I was thinking something like this: def over_user_limit? self.individual_plan? && self.users.count > INDIVIDUAL_USER_LIMIT end but I am stuck on how to do this with multiple user types? Any assistance here would be greatly appreciated. |
form_tag + file_field_tag causes the controller to respond to format.html? Posted: 15 Oct 2016 04:02 AM PDT my routes.rb: post 'home/review' my home_conrtoller.rb: def review @review = Review.new(review_params) @review.image = params[:review][:image] if @review.save respond_to do |format| format.js { render 'review', locals: {review_name: @review.review_name, review_body: @review.review_body} } end else format.html { respond_to root_path} end end private def review_params params.require(:review).permit(:review_name, :review_body, :image) end my review.js: $(function() { var theHTML = []; theHTML.push('somewhat'); $(".wrap-body").append(theHTML.join('')); }); my index.html.erb <%= form_tag home_review_path, :method => 'post', :multipart => true, :remote => true do %> <%= text_area_tag 'review[review_body]'%> <%= text_field_tag 'review[review_name]'%> <%= file_field_tag 'review[image]' %> <==== problem !!! <%= submit_tag 'Send'%> <%end %> Problem: if I add <% = file_field_tag 'review [image]'%> in a index.html.erb, rails throws an error: ActionController :: UnknownFormat in HomeController#review but if the field <% = file_field_tag 'review [image]'%> in a index.html.erb rails no returns review.js !!! How to change the index.html.erb or action in home_controller.rb that always rails returns an review.js never reload the page? Sorry for my English (( |
How can i pass a Bootstrap Datepicker range in a button_to Posted: 14 Oct 2016 11:37 PM PDT I've been looking a lot of solutions but none its like im thinking: I have this code in a .html.erb: <div class="input-daterange input-group" id="datepicker" > <span class="input-group-addon">Desde</span> <input type="text" class="input-sm form-control" name="start" /> <span class="input-group-addon">Hasta</span> <input type="text" class="input-sm form-control" name="end" /> </div> And I want to add a button_to like the following: <%= button_to "Solicitar", requests_path(current_user.id), :action => 'create', :method => :post, :class => 'btn btn-xs btn-primary', #Parametros params: { :accommodation_id => @auxHId, :accommodation_owner => @auxOwner, :requester => current_user.id, :initial_date => start, # <-- :final_date => end } # <-- %> How can I do to pass those "start" and "end" values? |
Ruby on Rails install bundle error Posted: 14 Oct 2016 10:26 PM PDT I am trying to install an github app developed by someone else and I am getting an error. I have searched the internet and tried a ton of suggestions but none seem to work. I am running OSX 10.11, I successfully installed RoR and I can get a new app to run. This git uses ruby v 2.0.0-p195. I tried to run 'bundle update' and get a similar error. I tried suggestions from this page: ruby-debug Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers And here: Error installing debugger: Failed to build gem native extension with ruby-1.9.3-p362 and a few other but no luck. I am including the entire terminal feedback in hopes someone can guide me. I am new to RoR so please help. The git source `git://github.com/imagesnap/paperclip-meta` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure. Fetching gem metadata from http://rubygems.org/............ Fetching version metadata from http://rubygems.org/.. Fetching dependency metadata from http://rubygems.org/. Using rake 11.1.2 Using i18n 0.7.0 Using multi_json 1.11.2 Using builder 3.0.4 Using erubis 2.7.0 Using journey 1.0.4 Using rack 1.4.7 Using hike 1.2.3 Using tilt 1.4.1 Using mime-types 1.25.1 Using polyglot 0.3.5 Using json 1.8.3 Using arel 3.0.3 Using tzinfo 0.3.48 Using addressable 2.4.0 Using mini_portile2 2.0.0 Using bcrypt-ruby 3.0.1 Using cancan 1.6.10 Using ffi 1.9.10 Using rubyzip 1.2.0 Using websocket 1.2.3 Using coderay 1.1.1 Using coffee-script-source 1.10.0 Using execjs 2.6.0 Using thor 0.19.1 Using columnize 0.9.0 Using daemons 1.2.3 Using database_cleaner 0.7.2 Using debugger-linecache 1.2.0 Using debugger-ruby_core_source 1.3.8 Using diff-lcs 1.2.5 Using eventmachine 1.2.0.1 Using multipart-post 2.0.0 Using formatador 0.2.5 Using rb-fsevent 0.9.7 Using lumberjack 1.0.10 Using nenv 0.3.0 Using shellany 0.0.1 Using method_source 0.8.2 Using slop 3.6.0 Using hashie 3.4.3 Using mini_magick 4.5.1 Using mixpanel-ruby 2.2.0 Using bundler 1.13.2 Using sixarm_ruby_unaccent 1.1.1 Using pg 0.18.4 Using rspec-support 3.4.1 Using sass 3.4.22 Using sequel 3.20.0 Using temple 0.7.6 Using will_paginate 3.1.0 Using faker 1.0.1 Using activesupport 3.2.22.2 Using braintree 2.59.0 Using rack-cache 1.6.1 Using rack-test 0.6.3 Using rack-ssl 1.3.4 Using rack-mobile-detect 0.4.0 Using sinatra 1.0 Using sprockets 2.2.3 Using rest-client 1.6.9 Using treetop 1.4.15 Using rdoc 3.12.2 Using launchy 2.2.0 Using nokogiri 1.6.7.2 Using childprocess 0.5.9 Using rb-inotify 0.9.7 Using zip-zip 0.3 Using coffee-script 2.4.1 Using uglifier 1.2.7 Using foreman 0.78.0 Installing debugger 1.6.8 with native extensions Using thin 1.6.4 Using faraday 0.9.2 Using notiffany 0.0.8 Using pry 0.10.3 Using money 6.7.0 Using rspec-core 3.4.4 Using rspec-expectations 3.4.0 Using rspec-mocks 3.4.1 Using slim 3.0.6 Using activemodel 3.2.22.2 Using active_utils 2.2.3 Using climate_control 0.0.3 Using delayed_job 3.0.3 Using factory_girl 3.2.0 Using taps 0.3.24 Using mail 2.5.4 Using letter_opener 1.4.1 Using aws-sdk-v1 1.66.0 Using xpath 0.1.4 Using selenium-webdriver 2.53.0 Using listen 3.0.6 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/debugger-1.6.8/ext/ruby_debug /Users/workplace/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20161015-62818-19849qb.rb extconf.rb *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/Users/workplace/.rbenv/versions/2.3.1/bin/$(RUBY_BASE_NAME) /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1392:in `initialize': No such file or directory @ rb_sysopen - ./231/ruby_debug.h (Errno::ENOENT) from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1392:in `open' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1392:in `copy_file' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:486:in `copy_file' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:403:in `block in cp' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1571:in `block in fu_each_src_dest' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1585:in `fu_each_src_dest0' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:1569:in `fu_each_src_dest' from /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/2.3.0/fileutils.rb:402:in `cp' from extconf.rb:83:in `block in <main>' from extconf.rb:82:in `each' from extconf.rb:82:in `<main>' extconf failed, exit code 1 Gem files will remain installed in /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/debugger-1.6.8 for inspection. Results logged to /Users/workplace/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/debugger-1.6.8/gem_make.out An error occurred while installing debugger (1.6.8), and Bundler cannot continue. Make sure that `gem install debugger -v '1.6.8'` succeeds before bundling. |
Shopping cart for registered and non registered users Posted: 14 Oct 2016 10:22 PM PDT I wanna build a shopping cart for items that users want to buy from popular shopping sites such as amazon. I don't know how cookies and sessions works on rails and which one is preferred for this case, so please I need your help ^^. I will be grateful if you mention some tutos or existing examples as well. Here is the steps : - As a non signed in user or non registered comes in
- He starts adding items to the shopping cart
- And by using cookies everything will be saved in the client side
- When he submits the order he will be redirected to sign in or register
- Once he signed in or registered, the order will be saved in the server, submitted and the cookies will be cleared.
item table class CreateItems < ActiveRecord::Migration def change create_table :items do |t| # the url of the item from a shopping website t.string :url t.timestamps null: false end end end |
how to concatenate environment variable with string in html Posted: 14 Oct 2016 10:26 PM PDT I am working on a rails project that uses html to send out an email. I pass the main domain through the environment variable EXTERNAL_URL. The button works as a clickable link when I have just the code below. <a href="<%= ENV['EXTERNAL_URL'] %>" class="btn-primary" ... However I am now trying to make the button point to a more specific path on the domain and I am trying to concatenate the strings like below but then the button is not clickable and is not working. <a href="<%= ENV["EXTERNAL_URL"+"/#/new_match"] %>" class="btn-primary" ... What is proper way to concatenate in this situation? |
In Ruby, how do I add multiple user input in f.number_field? Posted: 14 Oct 2016 10:03 PM PDT I'm a complete Ruby noob so please explain things to me like I'm 5. I have a form that has seven f.number_fields. I would like to add them and store them in :total. Here is an example of what I'm talking about: <%= f.label :icecream %><br> <%= f.number_field :icecream %> <%= f.label :cake %><br> <%= f.number_field :cake %> So in this case I would like to take the user input from :icecream and :cake and add them and store it in :total, but how would I do that? This would then be stored in the database. |
Great Article
B.Tech Final Year Projects for CSE in JavaScript
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai