EzDev.org

discourse

discourse - A platform for community discussion. Free, open, simple. Discourse


Tell Ember to rerender component

I've defined a component as follows:

export default Ember.Component.extend({
  classNameBindings: ['isCategory'],

  didInsertElement: function() {
    Ember.addObserver(Discourse, 'currentPath', this.routeChanged);
  },

  routeChanged: function(){
    var route = Discourse.get('currentPath');

    if (route == 'discovery.top') {
      this.set('path', '/top');
      this.set('label', 'top');
    } else if (route == 'discovery.categories'){
      this.set('path', '/categories');
      this.set('label', 'Categories');
    } else {
      this.set('path', '/latest');
      this.set('label', 'Latest');
    }
  },

  render: function(buffer) {
    this.routeChanged();
    buffer.push('<a rel='nofollow' href="' + this.get('path') + '">' + this.get('label') + '</a>');
  }
});

The logic (while not pretty) works as intended, however I don't know how to tell Ember to rerender the component when the value of path or label changes - I've tried using .observes() on the render function, as well as trying to call this.rerender() but this doesn't work.

Thanks

Edit:

Yes, of course I should not be manually rendering.

I now have a simple template:

<a rel='nofollow' href="{{path}}">{{label}}</a>

Backed by this component:

export default Ember.Component.extend({
  classNameBindings: ['isCategory'],
  templateName: "components/memory-nav",

  didInsertElement: function() {
    Ember.addObserver(Discourse, 'currentPath', this.routeChanged);
  }.on('init'),

  routeChanged: function(){
    var route = Discourse.get('currentPath');

    if (route == 'discovery.top') {
      Ember.Logger.log("Top");
      this.set('path', '/top');
      this.set('label', 'Top');
    } else if (route == 'discovery.categories'){
      Ember.Logger.log("Cateogries");
      this.set('path', '/categories');
      this.set('label', 'Categories');
    } else {
      Ember.Logger.log("Latest");
      this.set('path', '/latest');
      this.set('label', 'Latest');
    }
  }.on('init')
});

This now works, and the logs are being called correctly when the path changes. I would have thought that calling .set on the object would update the template automatically however this is not being updated at the moment. What am I missing?


Source: (StackOverflow)

How to get reference to current route from controller?

I have a controller (KbRelatedGroupController) that is loaded via a {{render}} helper in a template.

In the controller's action, if I do this.get('target'), it returns a reference to the parent controller for the page (KbShowController).

If I call .target on that, I get a reference to Discourse.Router, which is no good to me.

What I want is a reference to a KbShowRoute, and that is what I expected since .target is supposed to produce the Route when called from a controller is it not?

Really confused here. Why is it so hard to get a reference to the current route from a controller?


Source: (StackOverflow)

Alternative content if javascript web app encounters errors

Yesterday, I went to http://try.discourse.org, the new project developed by the Stack Overflow team. This project uses the EmberJs javascript Framework for requesting the content. And unfortunately my browser (Safari) sees the following error in the code:

TypeError: 'undefined' is not an object (evaluating 'PreloadStore.get("siteSettings").top_menu')

The consequence of this error is that no content is displayed; I have a blank page. The javascript error logically prevents the content from displaying.

My question is:

If javascript is disabled in my browser, I can see the content of Dicourse because of the <noscript> </noscript> tag in html.

But if I have javascript enabled and it encounters an error, I can see nothing.

So, in a web app development, is there a way to display the no script content or alternative content if the javascript app encounters an error?


Source: (StackOverflow)

Pass variable from initializer to handlebars .hbs (Discourse Plugin, maybe Ember in general)

In a .hbs file I am creating a navigation menu with various items. One of the items will only display if a user is a pro (boolean).

var pro is a variable set in my initializer and I need to pass it my .hbs file for the purposes of a conditionally showing one of the menu items.

In Ember, how is this accomplished?


Source: (StackOverflow)

Modify method in Ember Component

In the Discourse I want to modify method _dock. The modifying code will be placed in plugin.

Here's short snippet from that file:

export default Ember.Component.extend({
  elementId: 'topic-progress-wrapper',
  classNameBindings: ['docked', 'hidden'],

  ...
  _dock() {
    ...
  },

});

How to modify this method? Should I reopen this component and what is a syntax for that?


Source: (StackOverflow)

Heroku Deployment : Discourse Assets precompile

Hi I'm actually trying to deploy discourse on Heroku. I'm following the step by step guide here Basic Heroku deployment I'm facing a problem when I try to rake assets:precompile (I'm precompiling locally). The rake command is aborted, saying to me that

No such file or directory: mydirectories/discourse/config/database.yml

When I rake assets:precompile I'm in production environment (RAILS_ENV=production). So I checked if the database.yml was missing in the repo, and yes it was.

I currently have two database.yml but a bit different. There's database.yml.development-sample and database.yml.production-sample.

I tried renaming database.yml.production-sample to a simple database.yml but it still doesn't work giving me this error:

could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

What am I doing wrong ?

Cordially, Rob

PS : The config/redis.yml and public/assets are commented in the .gitignore


Source: (StackOverflow)

Setup discourse docker on mac os

I'm following standard guide to install discourse on my local mac. After launching the setup tool ./discourse-setup I've got error message:

cd /pups && git pull && /pups/bin/pups --stdin
/usr/local/bin/docker: Error response from daemon: Mounts denied: er.com/docker-for-mac/osxfs/#namespaces for more info.
.
r/discourse/shared/standalone/log/var-log
are not shared from OS X and are not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.

Initially I've tried to install to my work directory inside /Users. This folder is in File Sharing.

Then I installed to /var/discourse folder, the same error. I assumed that var folder is not in Docker File Sharing so I tried to add /var folder to Docker's Sharing Files and got message

The path /var is reserved by Docker

What might be a problem here?


Source: (StackOverflow)

Regex to normalize topic links in Discourse forum

I am using Discourse forum software. As in its current state, Discourse presents links to topic in two ways, with and without a post number at the end.

Example:

forum.domain.com/t/some-topic/23
forum.domain.com/t/some-topic/23/5

The first one is what I want and the second one I want to not be displayed in the forum at all.

I've written a post about it on Discourse forum but didn't receive an answer what Regex to put in the permalink normalization input field in the admin section.

I was told that there is an option to do it using permalink normalization like so (It's an example shown in the admin under the Regex input text, I didn't write it):

permalink normalizations

Apply the following regex before matching permalinks,
for example: /(topic.)\?./\1 will strip query strings from topic routes.
Format is regex+string use \1 etc. to access captures

I don't know what Regex I should use in order to remove the numerical value of the post number from links. I need it only for topic links.

This is the routes.rb routing library and this is the permalink.rb library (I think that the permalink library should help get a better clue how to achieve this). I have no idea how to approach this, because it seems that I need some knowledge of the Discourse routing to make it work. For example, I don't understand why (topic.) is part of the regex, what does it mean, so their example doesn't help me to find a solution.

In the admin I have an input field in which I nee to put the normalization regex code.

I need help with the Regex. I need the regex to work with all topics.

Things I've tried that didn't work out:

/(\/\d+)\/\d+$/\1

/(t/[^/]+/\d+).*/\1

/(\/\d+)\/[0-9]+$/\1

/(\/\d+)\/[0-9]+/\1

/(\/\d+)\/\d+$/\1/

/(forum.domain.com(\/\w+)*\/\d+)\/\d+(?=\s|$)/\1

Note: The Permalink Normalization input field treats the character | as a separator to separate between several Regex expressions.


Source: (StackOverflow)

Discourse bluepill to use rbenv

In official discourse repository there's a discourse.pill file for bluepill gem and it uses rvm.

Because I'm using rbenv I need that script to use rbenv (and I'm bad at environment stuff).

How I can convert this script, probably only this snippet of code?

bootup_bundle = [ "#{ENV['HOME']}/.rvm/bin/rvm/bootup_bundle",
                  "/usr/local/rvm/bin/rvm/bootup_bundle",
                  `which bootup_bundle`.strip,
                ].each do |location|
  if File.exist? location
    break location
  end
end

Source: (StackOverflow)

Discourse - Ruby 2.0 / Rails 4?

I know this is not the right type of question for Stack Overflow (please forgive me), but I've spent hours trying to get Discourse to run on my machine. It was working before, but I upgraded to Ruby 2.0 and Rails 4 and now I simply can't get it working due to various errors (mounting NFS, Syck deprecated, TheRubyRacer not installing properly).

I tackled these one by one, and now when I SSH into vagrant it says cannot find the gemfile when I do bundle install. I think I may have altered something and it's not "SSH-ing" into the proper folder, but I did a lot of things based on what I googled / found on stackoverflow and am kind of stuck.

I know this is a very vague / poorly structured question, but I'm still new to programming and just wondering, does Discourse work with Ruby 2.0/Rails 4 and can someone point me in the right direction regarding how to tell if I somehow broke my SSH command?


Source: (StackOverflow)

Creating a frame redirect causes Chrome to throw X-Frame-Options error

Refused to display 'http://sotaexchange.cloudapp.net/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

I redirect my domain sotaexchange.com to a Discourse forum but get the above error. If I switch it to an HTTP redirect there is no problem. I assume the problem is because my redirected to domain has the same text as the original domain and looks like trickery - what can I do to prevent this?

Edit

I am opening a bounty to get a better answer. For more info, I am currently using Windows Azure to host the discourse site and redirecting from a few other domains that I own. I don't want to use an HTTP redirect, I would like to use the Frame redirect.


Source: (StackOverflow)

Failed to connect to github.com port 443: Connection refused, Failed to Bootstrap, Discourse Docker

Whilst running my ./launcher bootstrap app command from /var/docker on a local installation of Discourse, I get this error.

fatal: unable to access 'https://github.com/SamSaffron/pups.git/': Failed to connect to github.com port 443: Connection refused
FAILED TO BOOTSTRAP

The following is the contents of my containers/app.yml. I've been using this guide to try to get it up and running. I've heard of some people having issues with HTTP connections refused due to iptables -L containing some rules blocking the docker container from connecting to the internet. But it moments before just downloaded an image. So I don't understand.

##
## After making changes to this file, you MUST rebuild for any changes
## to take effect in your live Discourse instance:
## 
## /var/docker/launcher rebuild app
##

## this is the all-in-one, standalone Discourse Docker container template
templates:
  - "templates/cron.template.yml"
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/sshd.template.yml"
  - "templates/web.template.yml"

## which TCP/IP ports should this container expose?
expose:
  - "127.0.0.1:20080:80"   # fwd host port 80   to container port 80 (http)
  - "2222:22" # fwd host port 2222 to container port 22 (ssh)

params:
  ## Which Git revision should this container use?
  version: HEAD

env:
  ## How many concurrent web requests are supported?
  ## With 2GB we recommend 3-4 workers, with 1GB only 2
  # UNICORN_WORKERS: 3
  ##
  ## List of comma delimited emails that will be made admin on signup
  DISCOURSE_DEVELOPER_EMAILS: <%= ENV['EMAIL_ADDRESS'] %>
  ##
  ## The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'localhost'
  ##
  ## The mailserver this Discourse instance will use
  DISCOURSE_SMTP_ADDRESS: smtp.gmail.com
  DISCOURSE_SMTP_PORT: 465
  DISCOURSE_SMTP_USER_NAME: <%= ENV['GMAIL_USERNAME'] %>
  DISCOURSE_SMTP_PASSWORD: <%= ENV['GMAIL_PASSWORD'] %>
  ##
  ## the origin pull CDN address for this Discourse instance
  # DISCOURSE_CDN_URL: //discourse-cdn.example.com

## These containers are stateless, all data is stored in /shared
volumes:
  - volume:
      host: /var/docker/shared/standalone
      guest: /shared

## The docker manager plugin allows you to one-click upgrade Discouse
## http://discourse.example.com/admin/docker
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"

  ## If you want to configure password login for root, uncomment and change:
  #- exec: apt-get -y install whois # for mkpasswd
  ## Use only one of the following lines:
  #- exec: /usr/sbin/usermod -p 'PASSWORD_HASH' root
  #- exec: /usr/sbin/usermod -p "$(mkpasswd -m sha-256 'RAW_PASSWORD')" root

  ## If you want to authorized additional users, uncomment and change:
  #- exec: ssh-import-id username
  #- exec: ssh-import-id anotherusername

  - exec: echo "End of custom commands"
  - exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'

Source: (StackOverflow)

Can't send mail with gmail stmp server (in discourse)

I'm trying to setup discourse, which is a rails3 webapp, but have some problems configuring smtp with gmail smtp server.

I have registered a new gmail account yesterday, and I can logged in browser and email-client software.

Then I configure discourse, in the file config/environments/production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address   => "smtp.gmail.com",
  :port      => "587",
  :user_name => "smtp4shuzu@gmail.com",
  :password  => "12345678",
  :authentication => :plain,
  :domain => "shuzhu.org",
  :enable_starttls_auto => true
}

Start the sidekiq which is used to sending the mails in the background:

nohup bundle exec sidekiq > log/sidekiq.log 2>&1 &

Then start discourse in production mode:

rails server -e production -d

But it doesn't work. I can see some errors in sidekiq.log:

2013-03-01T03:06:02Z 30687 TID-qib28 WARN: {"retry"=>true, "queue"=>"default", "class"=>"Jobs::UserEmail", "args"=>[{"type"=>"signup", "user_id"=>42, "email_token"=>"b40a21ece2b14586e346abfd96685975", "current_site_id"=>"default"}], "jid"=>"558bb6bd5aa36cfc8d3d1e91", "error_message"=>"Connection refused - connect(2)", "error_class"=>"Errno::ECONNREFUSED", "failed_at"=>2013-03-01 03:06:02 UTC, "retry_count"=>0} 2013-03-01T03:06:02Z 30687 TID-qib28 WARN: Connection refused - connect(2) 2013-03-01T03:06:02Z 30687 TID-qib28 WARN: /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in initialize' /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:inopen' /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'

I have tried all kinds of smtp settings, but none of them works.


UPDATE:

Per @Basil's answer, I just tried:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address   => "smtp.gmail.com",
  :port      => 587,
  :user_name => "smtp4shuzu",
  :password  => "12345678",
  :authentication => "plain",
  :enable_starttls_auto => true
}

But it has the same error. The domain shuzu.org is the domain of my site, I was thinking I should passing it to smtp. Now I removed it, but still not working.


Source: (StackOverflow)

How do I configure DATABASE_URL to add a list of host_names to database.yml on heroku?

Heroku generates database.yml from the DATABASE_URL environment variable like so: https://gist.github.com/liliakai/c161ad5704be04e88999

I'd like the resulting database.yml to include the line

host_names:  
  - my.customdomain.com

How would I encode this into the query string on the DATABASE_URL?


Source: (StackOverflow)

Is there any Ember event similar to `onload`

I want to execute JavaScript when all content (e.g. images) has been loaded in my Ember application.

I already tried using didInsertElement() and didRender() hooks, but it looks like they do not wait for background images to load.

Here's what my component's code snippet looks like:

export default Ember.Component.extend({
    didInsertElement() {
      this._super(...arguments);
      Ember.run.scheduleOnce('afterRender', this, function() {
        var home =$('#main-outlet')[0];
        home.className += " homePage";
        startTimer(5);
      });
    },
});

Any solution or an alternative approach for this?


Source: (StackOverflow)