samedi 27 juin 2015

Creating a priority ToDo App in Rails

I am trying to add a high/low priority button to a ToDo Rails app and am having trouble. The button should resort the items in the list based on high/low priority. I have created a new table with the rails generate method Priority, but I am having trouble on what I do next. How should you update the task controller to sort the tasks by order of priority?

How can I get the updated date from a bootstrap datetimepicker with the datetimepicker-rails gem

How can I get the value of the <input class="date_picker" ... when the <div class="bootstrap-datetimepicker-widget" ... is changed or updated? I need to get the value so I can update other attributes on the same page. Here is my best attempt to react to the 'changeDate' event:

$('.datetimepicker').datetimepicker().on('changeDate', function(ev){
    console.log(' date changed '+ ev.date); 
});

I'm unable to get any response form this event. I also opened an issue with @zpaulovics's gem but I'm not sure if this is a defect, or if I am not accessing the event correctly.

AngularJS HTTP call takes two minutes while the Rails action only takes 20 seconds, how can I debug this?

I have an AngularJS app and there's one page in my application, only one, that is taking 2 minutes to load. It is loading a bit of data, but the data itself is only 700KB and I benchmarked the entire rails action starting from the beginning until right before the render and it only takes 15-20 seconds. But when I look at the actual network call, or I put a timer before the angular http post call and then one in the success, they both show the call taking almost 2 minutes. I can't figure out what's going on between the render and the success on angular that would be causing this extreme time difference. Does anyone know how I could further debug this or possibly know what could be causing this?

The rails action just does a couple big database calls, all optimized, then does some work on the data, then the data (which is already JSONified with to_json) is rendered out.

Rails action ends with Completed 200 OK in 20458ms (Views: 913.8ms | ActiveRecord: 139.6ms)

Rails. Creating a User Controller. My Edit method does not show an ID

I'm creating a app. I've created a User Controller, and successfully created New and Create methods. Running the rails console, I can bring up any ID that I've created. I don't understand when I try to edit from the users/index.html page I'm not directed to /users/id/edit

Routes:

Prefix Verb   URI Pattern               Controller#Action
  users_index GET    /users/index(.:format)    users#index
welcome_index GET    /welcome/index(.:format)  welcome#index
       macros GET    /macros(.:format)         welcome#macros
         faqs GET    /faqs(.:format)           welcome#faqs
         root GET    /                         welcome#index
        users GET    /users(.:format)          users#index
              POST   /users(.:format)          users#create
     new_user GET    /users/new(.:format)      users#new
    edit_user GET    /users/:id/edit(.:format) users#edit
         user GET    /users/:id(.:format)      users#show
              PATCH  /users/:id(.:format)      users#update
              PUT    /users/:id(.:format)      users#update
              DELETE /users/:id(.:format)      users#destroy

UsersController:

class UsersController < ApplicationController
  def new

    @user = User.new
  end
  def create
    @user = User.new(set_user_params)
    if @user.save 
      redirect_to users_path
    else
    end
  end
  def index
    @users = User.all
  end
  def edit
    raise params.inspect
    @user = User.find(params[:id])
  end


  private 

    def set_user_params
      params.require(:user).permit(:name, :email, :team, :password)
    end
end

index.html

<div> <%= link_to "Create New Agent", new_user_path %></div>

<% @users.each.with_index(1) do |user, index| %>
    <div class="list_of_agents">
    <%= user.name %><br>
    <%= user.team %><br>
    <%= user.id %><br>
    <%= link_to "Edit", edit_user_path(user.id) %><br>
    </div>
<% end %>

Heroku migrate db error unknown column

I am working on my ruby on rails project and when I run heroku db:migrate I get an error about how a column doesn't exist.

I know that this is because I had a migration file that I manually edited to remove a column I created beforehand instead of creating a new migration file.

I removed the remove_column line and migrated db my local db but when I migrate it to heroku it still runs the migration file to remove column even though the line is no longer there on the actual file.

I dropped my database and loaded the schema again but the heroku error continues to occur.

Heroku scheduler - schedule on demand (http post?)

We want to schedule/trigger jobs over HTTP.

Currently, we are using Heroku scheduler (because it doesn't need extra dyno/free) to schedule jobs. We need an ability to schedule them via HTTP POST or some other mechanism that we can trigger programmatically.

Any suggestions on how we can achieve this?

How to generate 2D array from a set of string in rails?

I need to generate 2D array in rails from a set of given strings. For example:

days =[ "Monday",
     "Tuesday",
     "Wednesday",
  ]

Now I want to create a 2D array and the data in this array will be fill by from days string in random manner.

Example:

[monday, tuesday, wednesday],
[tuesday, wednesday, monday]
...

and so on depends on given dimensions

How to do it?