Rails: Displaying a user post form_for on a user page with nested routes Posted: 19 Sep 2016 08:22 AM PDT I'm building a facebook clone, and I'm trying to have a text area on each user's page to allow them to make posts. I've tried a whole bunch of different things with no success, but right now I am getting this error when trying to access the user's show page: First argument in form cannot contain nil or be empty with this code: Rails.application.routes.draw do resources :friends, only: [:index, :destroy] resources :posts resources :friend_requests devise_for :users devise_scope :user do root 'devise/sessions#new' end resources :users, only: [:index, :show] do resources :posts end get 'about', to: 'static_pages#about' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end _post_form.html.erb <%= form_for [@user, @post] do |f| %> <%= f.text_area :content, size: "60x12", placeholder: "What do you want to say?" %> <%= f.submit "Post" %> <% end %> class PostsController < ApplicationController def index @posts = Post.all end def new @post = Post.new @user = User.find_by(id: params[:id]) end def create @post = current_user.posts.build(post_params) if @post.save flash[:success] = "Posted!" redirect_to user_path(current_user) else flash[:notice] = "Post could not be submitted" redirect_to users_path end end private def post_params params.require(:post).permit(:content) end end class UsersController < ApplicationController def index @users = User.all end def show @user = User.find(params[:id]) end end users/show.html.erb <h4>You are signed in as <%= current_user.email %>! </h4> <% if @user == current_user %> <%= render "notifications" %> <%= render 'shared/post_form' %> <% end %> <%= params.inspect %> <%= current_user.id %> |
Unpermitted parameters error - Rails 4 with Devise and Active Admin Posted: 19 Sep 2016 08:20 AM PDT I have simple app created on Rails 4 and with Devise (for registrations and signing in). Problem: Can't save country_id parameter within creating or editing user. Note: Problem occurs only when I try to create/edit user from Active Admin panel. If I register user from my site's public side everything works. My form in user.rb file with permit params: form do |f| f.inputs "User Details" do f.input :email f.input :name, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 } f.input :country f.input :password,:input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 } f.input :password_confirmation, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 120 } f.input :role, as: :radio, collection: {Simple_user: "user"} f.input :bypass_humanizer, :value=> true,:as => :hidden end f.actions end permit_params :email, :password, :country_id,:bypass_humanizer,:password_confirmation, :role,:user, :in_blacklist, :admin_confirmed, :name My create action in admin/user.rb file: def create @user = User.new(user_params) if @user.save flash[:notice] = 'User was successfully created.' redirect_to admin_user_path(@user) else redirect_to :back flash[:notice] = 'Error accured. Please, check your data.' end end My log file: Started POST "/admin/users?locale=ru" for 85.254.76.28 at 2016-09-19 18:03:42 +0300 Processing by Admin::UsersController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"tmR9OsaNKREZb0l7J6gJb0E4G3bkmqSUrlduxMOVyQ8=", "user"=>{"email"=>"test7@individualki.eu", "name"=>"test7", "country_id"=>"1", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "role"=>"user", "bypass_humanizer"=>""}, "commit"=>"Create User", "locale"=>"ru"} [1m[36mCountry Load (0.5ms)[0m [1mSELECT `countries`.* FROM `countries` WHERE `countries`.`id` = 1 LIMIT 1[0m [1m[35mRegion Load (0.6ms)[0m SELECT `regions`.* FROM `regions` WHERE `regions`.`country_id` = 1 [1m[36mPartner Load (0.5ms)[0m [1mSELECT `partners`.* FROM `partners` WHERE `partners`.`id` = 1 LIMIT 1[0m [1m[35mUser Load (0.7ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 169 ORDER BY `users`.`id` ASC LIMIT 1 **Unpermitted parameters: country_id** [1m[36m (0.4ms)[0m [1mBEGIN[0m [1m[35mUser Exists (0.4ms)[0m SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'test7@individualki.eu' LIMIT 1 [1m[36mCACHE (0.0ms)[0m [1mSELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'test7@individualki.eu' LIMIT 1[0m [1m[35mUser Load (0.6ms)[0m SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = '08bf7322064e9569421c784e4fc4199be6ae20e4bc5ff960fdb49980fe0d018f' ORDER BY `users`.`id` ASC LIMIT 1 [1m[36mSQL (0.7ms)[0m [1mINSERT INTO `users` (`confirmation_sent_at`, `confirmation_token`, `created_at`, `email`, `encrypted_password`, `name`, `role`, `updated_at`) VALUES ('2016-09-19 18:03:42', '08bf7322064e9569421c784e4fc4199be6ae20e4bc5ff960fdb49980fe0d018f', '2016-09-19 18:03:42', 'test7@individualki.eu', '$2a$10$.NQgfnCbuH0ZUErcuL7vbO5x6BLQTZkZ9wiQFVkJvkJnCfc9ab38O', 'test7', 'user', '2016-09-19 18:03:42')[0m Rendered devise/mailer/confirmation_instructions.html.erb (4.5ms) What I have tried: 1) Double checked every place like users_controller, registration_controller and admin/user.rb file for permit_params line so country_id would be included. 2) Restarted server after every code change 3) Changed form so f.input :country would become f.input :country_id so I could fill in just simple number for country_id. |
Rails - nested form not saving my records Posted: 19 Sep 2016 08:24 AM PDT With my model: class Lab < ApplicationRecord has_many :business_days, dependent: :destroy accepts_nested_attributes_for :business_days, reject_if: lambda {|attributes| attributes['kind'].blank?} # ... end Controller: def new @lab = Lab 7.times { @lab.business_days.build} end I created a form to save my lab record to the database. I wanted to save available business days in one shot so I added this: <table class="table table-default"> <thead> <tr> <th></th> <% @weekdays.each do |day| %> <th class="text-center"><%= day[0..2].capitalize %></th> <% end %> </tr> </thead> <tbody> <tr> <th style="vertical-align: middle;">From:</th> <% @lab.business_days.each.with_index do |bd, index| %> <%= f.fields_for :business_days_attributes, index: index do |bd_form| %> <%= bd_form.hidden_field :day, value: @weekdays[index] %> <td><%= bd_form.text_field :from_time %></td> <% end %> <% end %> </tr> <tr> <th style="vertical-align: middle;">To:</th> <% @lab.business_days.each.with_index do |bd, index| %> <%= f.fields_for :business_days_attributes, index: index do |bd_form| %> <td><%= bd_form.text_field :to_time %></td> <% end %> <% end %> </tr> </tbody> </table> and what it does is explained in the picture: My create action looks like this: def create @lab = Lab.new(lab_params) if @lab.save end And lab_params definition looks like this: def lab_params return params.require(:lab).permit(:name, :street, :city, :postal_code, :state, :country, business_days_attributes: [:day, :from_time, :to_time]) end My problem is when I save try to submit the form the Lab record gets saved but no BusinessDay records is created/ saved. My question is - where did I make a mistake? EDIT - params as requested: Started POST "/labs" for ::1 at 2016-09-19 17:15:40 +0200 Processing by LabsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"sbiXra6IQBpleuCqZ+zUFN+mDAzjSa/b9VgCYz6kL2VyeTkiqcldy5SOVXJCHr3HrWbUMCjtlBUrjXOBrWOhHA==", "lab"=>{"name"=>"Laboratory Uno", "street"=>"some street", "city"=>"some city", "business_days_attributes"=>{"0"=>{"day"=>"monday", "from_time"=>"00:00", "to_time"=>"15:00"}, "1"=>{"day"=>"tuesday", "from_time"=>"", "to_time"=>""}, "2"=>{"day"=>"wednesday", "from_time"=>"", "to_time"=>""}, "3"=>{"day"=>"thursday", "from_time"=>"", "to_time"=>""}, "4"=>{"day"=>"friday", "from_time"=>"", "to_time"=>""}, "5"=>{"day"=>"saturday", "from_time"=>"", "to_time"=>""}, "6"=>{"day"=>"sunday", "from_time"=>"", "to_time"=>""}}}, "commit"=>"Add to database"} User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] (0.4ms) BEGIN SQL (0.6ms) INSERT INTO "labs" ("name", "street", "city", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "Laboratory Uno"], ["street", "some street"], ["city", "some city"], ["created_at", 2016-09-19 15:15:40 UTC], ["updated_at", 2016-09-19 15:15:40 UTC]] (0.5ms) COMMIT Redirected to http://localhost:3000/labs/7 Completed 302 Found in 17ms (ActiveRecord: 2.6ms) |
Intercept has_many association call Posted: 19 Sep 2016 08:08 AM PDT There are two models class Order < ... has_many :products def products products.count.zero? ? <some action> : products end end class Product < ... end I need to intercept products call on order: Order.first.products to replace output with some custom logic if there are no products or return associated products if there are. I have tried read_attribute but without success. |
Time conversion Ruby on Rails 4 not working Posted: 19 Sep 2016 08:23 AM PDT Part of my logic for sending an email to a supplier is that the promise date must be less than today's date in order to send the email. For whatever reason, it is passing as true even though it should be false. I test it in the console and it shows false, but it sends the email... so I am guessing it is passing as true. def self.send_vendor_openorder_notification(user, vendor) po_collection = Array.new user.purchase_orders.where({open_order: true, vendor_number: vendor.vendor_number}).where.not(email_last_sent: Time.now.midnight).each do |x| if x.promise_date == nil || DateTime.strptime(x.promise_date, '%m/%d/%y') + 7.hours < Time.now.midnight if x.email_sent == false po_collection << x.id x.email_sent = true x.email_last_sent = Time.now.midnight x.save end end end if po_collection.empty? == false VendorSender.open_order_sender(user, vendor, po_collection).deliver_later end end Here if promise_date is nil or less than today at midnight, it should pass. However, a promise date of "09/19/2016" is passing as true on 09/19/2016. In heroku console(this is deployed through Heroku), this is false... What am I missing here? irb(main):038:0> DateTime.strptime("09/19/16", '%m/%d/%y') + 7.hours < Time.now.midnight => false irb(main):039:0> DateTime.strptime("09/19/16", '%m/%d/%y') + 7.hours => Mon, 19 Sep 2016 07:00:00 +0000 irb(main):040:0> Time.now.midnight => 2016-09-19 00:00:00 -0700 irb(main):041:0> |
Test SessionsConstroller Devise + RSpec Posted: 19 Sep 2016 08:01 AM PDT I have this custom create method on SessionsController: def create puts "!!!!!!!!!!!!!!!" if view_only? login_visualizacao return end puts "1111111111111111" super puts "2222222222222222" set_token current_usuario, nil unless !current_usuario end And trying to test this using RSpec, like this: require 'spec_helper' describe Usuarios::SessionsController do# do, :type => :controller do describe 'Realizar login' do let(:codigo) { '1020' } let(:senha) { '12345' } context 'quando o login via API é feito corretamente' do # let(:user) { Usuario.new(codigo: codigo, password: senha) } let(:user) { mock_model(Usuario, codigo: codigo, password: senha) } before do setup_controller_for_warden @request.env["devise.mapping"] = Devise.mappings[:usuario] allow(user).to receive(:authenticatable_salt) allow(subject).to receive(:super) sign_in(user) # allow(subject).to receive(:current_usuario).and_return(user) allow(subject).to receive(:set_token) end end end end I put these lines of code in my spec_helper: config.include Devise::TestHelpers, type: :controller config.include Devise::TestHelpers, type: :request The problem is that my RSpec test isn't printing "2222222222", I think the super code isn't being executed successfully, the user isn't being logged and therefore the current_usuario is nil. I don't know whatelse is missing, can anybody help me? How can I mock the call to super method? |
Correct way to require Payment API in Rails Posted: 19 Sep 2016 07:58 AM PDT I'm trying to integrate Mollie Payments using the Mollie API I added the gem to my gemfile and ran bundle install. After that i did this to my existing controller: class PagesController < ApplicationController require 'Mollie/API/Client' def form_page mollie = Mollie::API::Client.new mollie.api_key = 'test_SKQzVUv7Rs7AUqmW7FdTvF9SbEujmQ' payment = mollie.payments.create( amount: 10.00, description: 'My first API payment', redirectUrl: '/index' ) payment = mollie.payments.get(payment.id) if payment.paid? puts 'Payment received.' end end def success end end Where form_page is the 'new' method and 'success' is the page where it should redirect to after payment has succeeded. But when going to the form_page view i get this error: NoMethodError (undefined method `api_key=' for #<Mollie::API::Client:0x007fa6fb8>) So my guess is that the API isn't required the right way or something like that. Anybody has an idea on what i'm doing wrong? Any help would be much much appreciated!! |
Generating special secure id Posted: 19 Sep 2016 07:47 AM PDT I have to generate a unique reference in the format similar to ABC-4F-ABC-8D-ABC (where: ABC is random 3-char string, 4F, 8D are random hex numbers). I am a new guy to ruby, so please forgive me if this is duplicate(did not found smth that is similar so far). So are there any libs that could help me to generate this or should I play with this myself? |
Rails convert model to string separated with comma Posted: 19 Sep 2016 08:03 AM PDT I have a rails object, for example : Book {id:1, name: "name1"} Book {id:2, name: "name2"} I use the DataTables and the best ajax data is get the object as an string array, without the columns name. How can I change the Book.all to array of data without columns names The expected results is like this Thanks { "data": [ [ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800" ], [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750" ], [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000" ] ] } |
' ' is not a supported controller name error in Rails Server Start Posted: 19 Sep 2016 07:39 AM PDT I get this error when I try to start Rails Server. It looks like something is missing from Rails ... I have tried updating, and digging through the file listed. I am not sure what caused this, it worked in the afternoon and didn't in the evening??? Sorry for the long error message coming up, but I am kind of new to Rails, and am not sure what you all will need to help me find an answer. Here it goes - rails s => Booting Puma => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Run rails server -h for more startup options Exiting /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:313:in block (2 levels) in check_controller_and_action': '' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError) from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:358:in translate_controller' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:309:in block in check_controller_and_action' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:324:in check_part' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:308:in check_controller_and_action' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:251:in normalize_options!' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:115:in initialize' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:68:in new' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:68:in build' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:1698:in add_route' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:1670:in decomposed_match' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:1634:in block in match' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:1617:in each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:1617:in match' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:722:in map_method' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:680:in get' from /Users/joseph/Documents/Rails/jwm/config/routes.rb:9:in block in <top (required)>' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in instance_exec' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:389:in eval_block' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:371:in draw' from /Users/joseph/Documents/Rails/jwm/config/routes.rb:1:in <top (required)>' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in load' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in block in load' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in load_dependency' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in load' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in block in load_paths' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:40:in load_paths' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:16:in reload!' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:26:in block in updater' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/file_update_checker.rb:77:in execute' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:27:in updater' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/routes_reloader.rb:7:in execute_if_updated' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:119:in block in ' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in instance_exec' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in run' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in block in run_initializers' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in block in tsort_each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in each_strongly_connected_component_from' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in block in each_strongly_connected_component' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in call' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in each_strongly_connected_component' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in tsort_each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in tsort_each' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in run_initializers' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in initialize!' from /Users/joseph/Documents/Rails/jwm/config/environment.rb:5:in <top (required)>' from /Users/joseph/Documents/Rails/jwm/config.ru:3:in require_relative' from /Users/joseph/Documents/Rails/jwm/config.ru:3:in block in <main>' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in instance_eval' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in initialize' from /Users/joseph/Documents/Rails/jwm/config.ru:in new' from /Users/joseph/Documents/Rails/jwm/config.ru:in <main>' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in eval' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:49:in new_from_string' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/builder.rb:40:in parse_file' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:318:in build_app_and_options_from_config' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:218:in app' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/server.rb:59:in app' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/server.rb:353:in wrapped_app' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/server.rb:124:in log_to_stdout' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/server.rb:77:in start' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:90:in block in server' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in tap' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in server' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in run_command!' from /Users/joseph/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in <top (required)>' from bin/rails:4:in require' from bin/rails:4:in `' |
In RoR, how do I send an https request over a socks port? Posted: 19 Sep 2016 07:37 AM PDT I'm using the below code to retrieve a web page through SOCKS uri = URI(url) content = nil status = nil content_type = nil res1 = Net::HTTP.SOCKSProxy('127.0.0.1', 50001).start(uri.host, uri.port) do |http| puts "launching #{uri.path}" resp = http.get(uri.path) status = resp.code content = resp.body content_type = resp['content-type'] end In advance, I don't know if the url is going to be "http" or "https". When I try and connect to an https port, it appears the request is still sent over http as evidenced by below … doc = WebpageHelper.get_url("https://whatismyip.com/") which actually results in 2.3.0 :013 > doc.to_s => "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html>\r\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>400 The plain HTTP request was sent to HTTPS port</title>\n</head>\r\n<body bgcolor=\"white\">\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>The plain HTTP request was sent to HTTPS port</center>\r\n<hr>\n<center>cloudflare-nginx</center>\r\n</body>\r\n</html>\n" Is there something I need to set in the above that can force the request over https if it is actually an https web page? |
Connect to Windows SQL Server 2008 R2 from Rails app Posted: 19 Sep 2016 07:31 AM PDT My Rails 4.2.1 app has to connect to a Microsoft SQL 2008 R2 database. I am using the tiny_tds gem version 1.0.4. freetds is installed on the production server running Ubuntu 14.04. I can't manage to have queries returning a lot of results to run properly. I tried playing with tiny_tds options without success. This is what I am using to get the tiny_tds client (check tds_version and timeout options): client = TinyTds::Client.new(username: db_conf['username'], password: db_conf['password'], host: db_conf['host'], port: db_conf['port'], database: db_conf['database'], tds_version: '7.3', timeout: 25) packet.c:741:Sending packet 0000 12 01 00 ce 00 00 00 00-16 03 01 00 86 10 00 00 |........ ........| 0010 82 00 80 6e d9 e2 dc 97-9d 77 59 9a 5b da e3 e2 |...n.... .wY.[...| 0020 8b aa 66 ed ec 5e e2 02-e5 6c fd db e1 ef 47 1a |..f..^.. .l....G.| 0030 9d 63 03 ed 6d 3e 28 3b-b9 64 fd 92 71 34 ff ba |.c..m>(; .d..q4..| 0040 7d 3c 8d ee 7b 34 75 e9-d5 b7 c6 83 a9 7d e6 7f |}<..{4u. .....}..| 0050 71 7e 25 11 82 b8 76 b1-c6 ba 86 b4 c3 0a 47 f0 |q~%...v. ......G.| 0060 51 96 c7 e2 5f ca 07 b2-95 53 b9 9e bb 2c e7 cb |Q..._... .S...,..| 0070 be 0a b5 eb b0 f3 41 1d-cd 86 fc a6 53 08 5e 56 |......A. ....S.^V| 0080 29 85 79 14 dc 2b 74 7b-b2 43 2c e8 0e 87 60 e4 |).y..+t{ .C,....| 0090 10 ef f8 14 03 01 00 01-01 16 03 01 00 30 c7 f0 |........ .....0..| 00a0 35 f5 2c 6e 79 8d 85 b9-bd 60 b7 09 8c 7e 29 18 |5.,ny... . ...~).| 00b0 4a 56 ea c3 4e 13 bf e3-c5 8d f6 68 31 31 54 ee |JV..N... ...h11T.| 00c0 bf 2f 75 8d e9 9e c0 a9-d0 d2 9e 5b c9 92 |./u..... ...[..| tls.c:105:in tds_pull_func_login query.c:3796:tds_disconnect() util.c:165:Changed query state from IDLE to DEAD util.c:322:tdserror(0x80b75e0, 0xa04ca80, 20017, 0) dblib.c:7947:dbperror(0xae62780, 20017, 0) dblib.c:8015:dbperror: Calling dblib_err_handler with msgno = 20017; msg->msgtext = "Unexpected EOF from the server (192.168.32.105:1433)" dblib.c:5777:dbgetuserdata(0xae62780) dblib.c:8037:dbperror: dblib_err_handler for msgno = 20017; msg->msgtext = "Unexpected EOF from the server (192.168.32.105:1433)" -- returns 2 (INT_CANCEL) util.c:352:tdserror: client library returned TDS_INT_CANCEL(2) util.c:375:tdserror: returning TDS_INT_CANCEL(2) util.c:375:tdserror: returning TDS_INT_CANCEL(2) tls.c:942:handshake failed login.c:530:login packet rejected util.c:322:tdserror(0x80b75e0, 0xa04ca80, 20002, 0) dblib.c:7947:dbperror(0xae62780, 20002, 0) dblib.c:8015:dbperror: Calling dblib_err_handler with msgno = 20002; msg->msgtext = "Adaptive Server connection failed" Any idea what I should do to fix those Unexpected EOF from the server errors? |
ActionView::MissingTemplate on initial attempt to deliver email with Sidekiq Posted: 19 Sep 2016 07:24 AM PDT I keep getting errors reported to Honeybadger that various mailer fail from being unable to find the template like: ActionView::MissingTemplate: Missing template user_mailer/send_invitation with "mailer". Searched in: * "user_mailer" . I have found a way I can reliably reproduce it is by restarting the Unicorn workers or ssh'ing into the server and using the Rails console to manually trigger the email. To make things more interesting, it only throws this error if I use deliver_later but not if I use deliver_now . Obviously I want to deliver emails asynchronously, so using deliver_now isn't really an option unless I make my own job that trigger the email manually, but that doesn't seem optimal. Sidekiq.yml production: :concurrency: 10 :queues: - default - mailers - elasticsearch - searchkick It still delivers the emails on the second attempt, so I'm not sure if this has to do with some loading of Sidekiq or something. Any help is greatly appreciated. Using Rails 5.0.0, Sidekiq 4.1.4, and ActiveJob 5.0.0. |
Rails: i18n translation of a string stored in the database Posted: 19 Sep 2016 07:21 AM PDT I have a table with columns that contain a string. For simplicity let's say the possible values are 'Apple', 'Pear', 'Banana', stored in the DB in English. For my different locales I wish to translate this string using i18n. My guess was to add to my nl.yml "Apple": "Appel" "Pear": "Peer" "Banana": "Banaan" And then add to my view <%= t(@fruit.name) %> But this does not quite work as expected. Any suggestions? |
Rails: uniq vs. distinct Posted: 19 Sep 2016 07:43 AM PDT Can someone briefly explain to me the difference in use between the methods uniq and distinct ? I've seen both used in similar context, but the difference isnt quite clear to me. |
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead Posted: 19 Sep 2016 07:15 AM PDT I get the following error message when I run the command rails g spree:install which I am using in my Rails app. DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /Users/stevenaguilar/Desktop/store/store/config/application.rb:7) /Users/stevenaguilar/.rvm/gems/ruby-2.2.3/gems/bundler-1.13.1/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'spree'. Gem Load Error is: No connection pool with id primary found. Backtrace for gem load error is: /Users/stevenaguilar/.rvm/gems/ruby-2.2.3/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `retrieve_connection' I believe there has to be an issue with the edition of Rails that I am using so I updated my Gemfile. source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0', '>= 5.0.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' gem 'nokogiri', '~> 1.6', '>= 1.6.8' #gem rack gem 'rack', '~> 2.0', '>= 2.0.1' #Rspec for testing gem 'rspec', '~> 3.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :rails_adminelopment gem 'spree' 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' gem 'listen', '~> 3.0.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] I tried following the answers to some of the other posts but still haven't find any luck fixing this issue. I tried updating the spree gem but it didn't work. |
Defining a custom route in a namespaced api in rails application Posted: 19 Sep 2016 07:20 AM PDT I have created a namespaced api in my rails 5 project. I have the following in my config/routes.rb Rails.application.routes.draw do post 'api_user_token' => 'api_user_token#create' namespace :api do namespace :v1 do resources :events end end end Events Controller module Api::V1 class EventsController < ApiController #Code here end end API Controller module Api::V1 class ApiController < ApplicationController before_action :authenticate_api_user respond_to :json def register end end end I want the '/api/v1/register' route to go to the register method defined in my api controller. How can i define the route in this case ? Thanks |
Creating a notification in ruby on rails 4 Posted: 19 Sep 2016 07:09 AM PDT I need help with getting a badge notification on the web application if one column of my model has changed, can I use the Observables? since this is the closest I think might work, if so how can I implement it in a like class Car < ApplicationRecord end Or is it possible to implement an Observable in the Controllers? def update respond_to do |format| if @car.update(car_params) format.html { redirect_to @car, notice: 'Car was successfully updated.' } format.json { render :show, status: :ok, location: @car } else format.html { render :edit } format.json { render json: @car.errors, status: :unprocessable_entity } end end end |
Double Render Error rails controller Posted: 19 Sep 2016 07:33 AM PDT So i'm tyring ot create a custom method in my controller So far it looks like this def url require 'json' url = url appears here doc = Nokogiri::HTML(open(url)) doc.css(".ticket-price .h4").each do |t| json = t.text respond_to do |format| format.json { render :json => {:seatname => json}} end end end However when i run this i get this error AbstractController::DoubleRenderError I can't see where the its being called twice? my guess however is that because its inside the each statement. What would be the best way to display the two seat names that come back in json so that it looks like this: "seatname": "seat1", "seatname": "seat2" Thanks Sam |
Rails 4: Check if today is sunday, 15th of month or last day of month Posted: 19 Sep 2016 07:09 AM PDT A sidekiq worker sending PDF attachment in emails to clients. The worker runs daily checking if its Sunday then sends weekly report, if today is 15th of month then Bi-monthly report and if last day of month then monthly report. The condition looks something like this: if sunday? # send weekly elsif 15th of month # send Bi-monthly elsif last_day_of_month # send Monthly end How to check if its sunday, 15th of month and last day of month ? |
Error in joins Rails Posted: 19 Sep 2016 08:09 AM PDT im trying to join 2 tables on rails but its becoming imposible to me. My schema is: table "cursos"| t.string "nombre" t.integer "user_id" end table "users", t.string "name" end user.rb: class User < ActiveRecord::Base has_many :cursos curso.rb class Curso < ActiveRecord::Base belongs_to :user def self.search(nameProf) (Cursos.joins(:users).where("users.name ilike ?", "%#{nameProf}%").all) end its giving me this error: NameError in CursosController#index uninitialized constant Curso::Cursos thanks! |
Rails Active Admin - Download Table as CSV for a table that isn't resource Posted: 19 Sep 2016 06:53 AM PDT Hi Have a page in my active admin that aggregates data from different resources. (using Rails 4) I can see how I can do (and even customize it for a single resource), but is there a way do download as CSV a table which isn't composed of a single resource? Here is my cool table that I want to download: ActiveAdmin.register_page "My_cool_table" do content do table_for User.all.each do column "User Email" do |user| user.settings.email end column "Utm Source", :utm_source column "Utm Medium", :utm_medium column "Utm Campaign", :utm_campaign end end end Thanks!! |
gems for video upload Rails - Paperclip? Posted: 19 Sep 2016 06:47 AM PDT Have added paperclip-av-transcoder gem to upload videos (Images & gifs upload already set up) Read over different examples for video upload though each throw out errors or are very different examples and as yet have not found a clear example. Some mention to add to the schema/migrate and others seem to talk of adding a folder extension and then convert. Is it possible to add video to a current 'contacts' model and to the schema so it can be uploaded and sent/requested to and from the DB? Is anyone aware of a clear example of this? |
Ruby on Rails novice, how to redirect site to image? Posted: 19 Sep 2016 06:47 AM PDT For you Ruby on Rails fans, this might be a very simple question. I have been handed control of a RR site (none on our team handle RR), which is in the middle of being completely rebuilt with PHP. In the mean time, the client has requested that the existing site display only an image, nothing more. - The image would be hosted within the "public" folder within the RR framework.
- They want the entire site to become an un-clickable image.
What is the easiest way to do this? What would the code look like and where do I put that code? I have attempted to change the routing code, but that has had no effect. I didn't even break the website. I would appreciate any RR help! |
RSpec: Controller spec with polymorphic resource, "No route matches" error Posted: 19 Sep 2016 06:34 AM PDT I'm learning RSpec by writing specs for an existing project. I'm having trouble with a controller spec for a polymorphic resource Notes. Virtually any other model can have a relationship with Notes like this: has_many :notes, as: :noteable In addition, the app is multi-tenant, where each Account can have many Users. Each Account is accessed by :slug instead of :id in the URL. So my mulit-tenant, polymorphic routing looks like this: # config/routes.rb ... scope ':slug', module: 'accounts' do ... resources :customers do resources :notes end resources :products do resources :notes end end This results in routes like this for the :new action new_customer_note GET /:slug/customers/:customer_id/notes/new(.:format) accounts/notes#new new_product_note GET /:slug/products/:product_id/notes/new(.:format) accounts/notes#new Now on to the testing problem. First, here's an example of how I test other non-polymorphic controllers, like invitations_controller: # from spec/controllers/accounts/invitation_controller_spec.rb require 'rails_helper' describe Accounts::InvitationsController do describe 'creating and sending invitation' do before :each do @owner = create(:user) sign_in @owner @account = create(:account, owner: @owner) end describe 'GET #new' do it "assigns a new Invitation to @invitation" do get :new, slug: @account.slug expect(assigns(:invitation)).to be_a_new(Invitation) end end ... end When i try to use a similar approach to test the polymorphic notes_controller, I get confused :-) # from spec/controllers/accounts/notes_controller_spec.rb require 'rails_helper' describe Accounts::NotesController do before :each do @owner = create(:user) sign_in @owner @account = create(:account, owner: @owner) @noteable = create(:customer, account: @account) end describe 'GET #new' do it 'assigns a new note to @note for the noteable object' do get :new, slug: @account.slug, noteable: @noteable # no idea how to fix this :-) expect(:note).to be_a_new(:note) end end end Here I'm just creating a Customer as @noteable in the before block, but it could just as well have been a Product. When I run rspec, I get this error: No route matches {:action=>"new", :controller=>"accounts/notes", :noteable=>"1", :slug=>"nicolaswisozk"} I see what the problem is, but i just can't figure out how to address the dynamic parts of the URL, like /products/ or /customers/ . Any help is appreciated :-) |
RuntimeError: #let or #subject called without a block Posted: 19 Sep 2016 06:29 AM PDT This is my first rspec test I was using Hurtl's tutorial and figured that it is outdated. I want to change this line because its is no longer a part of rspec: its(:user) { should == user } I tried to do this: expect(subject.user).to eq(user) But get an error RuntimeError: #let or #subject called without a block This is my full rspec test if you need it: require 'spec_helper' require "rails_helper" describe Question do let(:user) { FactoryGirl.create(:user) } before { @question = user.questions.build(content: "Lorem ipsum") } subject { @question } it { should respond_to(:body) } it { should respond_to(:title) } it { should respond_to(:user_id) } it { should respond_to(:user) } expect(subject.user).to eq(user) its(:user) { should == user } it { should be_valid } describe "accessible attributes" do it "should not allow access to user_id" do expect do Question.new(user_id: user.id) end.to raise_error(ActiveModel::MassAssignmentSecurity::Error) end end describe "when user_id is not present" do before { @question.user_id = nil } it { should_not be_valid } end end |
Upgrade rails 4.1 to 4.2 column name issue Posted: 19 Sep 2016 06:45 AM PDT I'm running a few years old pretty big Rails 4.1 App, where one of the central models has a column called model_name . After the failed attempt to upgrade the app to rails 4.2, we have found out, that this column name is actually a rails reserved word. This did not come to our attention before, since the rails method which used the name, was a private method. Now, since rails 4.2 this is public, and rails complains big time over the naming confusion. I really really really don't wanna rename the column, since it's referenced everywhere in our application, even in a lot of serialized data, historic URL's etc. Any suggestions on an alternative upgrade procedure other than renaming the column? |
Trying to create a plugin in rails (2.3.5) Posted: 19 Sep 2016 04:53 AM PDT i am currently working in a old version of rails(2.3.5) and ruby(1.8.7) just followed the rails guideto create plugin, when running the rake command it shows the following error! /usr/local/bin/ruby -I"lib:lib:test" "/usr/local/lib/ruby/gems/1.8 gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/yaffle_test.rb" "test/core_ext_test.rb" -- create_table(:hickwalls, {:force=>true})-> 0.3919s -- create_table(:wickwalls, {:force=>true})-> 0.3297s -- create_table(:woodpeckers, {:force=>true})-> 0.3370s -- initialize_schema_migrations_table()-> 0.0005s -- assume_migrated_upto_version(0)-> 0.0002s /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- ./test/../rails/init.rb (MissingSourceFile) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib /active_support/dependencies.rb:158:in `require' from ./test/test_helper.rb:34:in `load_schema' from ./test/yaffle_test.rb:7 from /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib /rake/rake_test_loader.rb:5:in `load' from /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib rake/rake_test_loader.rb:5 from /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib /rake/rake_test_loader.rb:5:in `each' from /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib /rake/rake_test_loader.rb:5 rake aborted! Command failed with status (1): [/usr/local/bin/ruby -I"lib:lib:test" "/usr...] |
Creating custom app via Ruby on Rails Posted: 19 Sep 2016 07:50 AM PDT I'm new here. I'm trying to create custom (private) app for making recurring billing. I'm using ror (ruby on rails) gem shopifyAPI 7.2.0. I can get products from cart on my server, using cart's token. So then I'm trying to create checkout object, but I don't know how should I do it. I'm trying to create new checkout object, put there "line items" from cart and save it, but I get next message "Response code = 403. Response message = Forbidden". As I understand I don't have permission for this, but why? Can someone explain how to create checkout and charge it? |
Unable to render anything using angular js on RoR Posted: 19 Sep 2016 04:43 AM PDT I am following this tutorial https://thinkster.io/angular-rails to setup angular js on RoR. I am stuck here as it is not rendering home.html partial present with in assets/javascripts/home/_home.html. browser shows blank screen even though i have added html and angular in _home.html. please help me out app.js angular.module('flapperNews', ['ui.router','templates']) .config([ '$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $stateProvider .state('home', { url: '/home', templateUrl: 'home/_home.html', controller: 'MainCtrl', resolve: { postPromise: ['posts', function(posts){ return posts.getAll(); }] } }) .state('posts', { url: '/posts/{id}', templateUrl: 'posts/_posts.html', controller: 'PostsCtrl' }); $urlRouterProvider.otherwise('home'); }]) application.js //= require jquery //= require jquery_ujs //= require angular //= require angular-ui-router //= require angular-rails-templates //= require_tree . _home.html <script type="text/ng-template" id="/home.html"> <div class="page-header"> <h1>Flapper News</h1> </div> <div ng-repeat="post in posts | orderBy:'-upvotes'"> <span class="glyphicon glyphicon-thumbs-up" ng-click="incrementUpvotes(post)"></span> {{post.upvotes}} <span style="font-size:20px; margin-left:10px;"> <a ng-show="post.link" href="{{post.link}}"> {{post.title}} </a> <span ng-hide="post.link"> {{post.title}} </span> </span> <span> <a href="#/posts/{{$index}}">Comments</a> </span> </div> <form ng-submit="addPost()" style="margin-top:30px;"> <h3>Add a new post</h3> <div class="form-group"> <input type="text" class="form-control" placeholder="Title" ng-model="title"></input> </div> <div class="form-group"> <input type="text" class="form-control" placeholder="Link" ng-model="link"></input> </div> <button type="submit" class="btn btn-primary">Post</button> </form> </script> application.html.erb <head> <title>Workspace</title> <%= stylesheet_link_tag 'application', media: 'all'%> <%= javascript_include_tag 'application'%> <%= csrf_meta_tags %> </head> <body ng-app="flapperNews"> <div class="row"> <div class="col-md-6 col-md-offset-3"> <ui-view></ui-view> </div> </div> </body> routes root to: 'application#angular' application_controller.rb def angular render 'layouts/application' end |
No comments:
Post a Comment