Direkt zum Hauptbereich

Posts

Posts mit dem Label "rails" werden angezeigt.

rails 4 with activerecord, devise, cancan and rolify for authentication/authorisation

Rails is a great tool and just recently I discovered the full potential of it, although I am still not using to the full. How do all these gems work together - why rolify? Devise does the authentication and uses a table named 'User' e.g. and gives the found user access to the specific part of your site. Now cancan joines the game and since you will have marked models or part of the site with roles, it checks if a user is allowed: authorised. Normally this is done through another column in the users table (you had to do yourself prior), but then you can assign one role to one user. Rolify uses another approach when assigning roles, it creates a joint table connecting the User model to the Role model. That "could" mean you can assign several roles to a user, e.g. moderate and also be a mini admin. Rolify bug: The migration file had no file extension, with this missing "rb" I chased after the error "could not find Role table". My Pro...

"Could not find table 'Role'" - rolify, devise, cancan and a silly mistake

I followed the tutorial on github on getting rolify up and running, but everytime I ran into the problem, that the table "Role" was not set up. I ran all migrations, even twice, but nothing. After about three quarters of an hour I found the solution on the issue tracker on github: the "rb" was missing from the migration file! Putting the RB behind the file and everything worked fine.

HAML

Yesterday I did some coding regarding the output of my diagnose! app. Doing that I discovered the ease of HAML over ERB/HTML. This is HTML and even it looks awful it would be parsed right: <div class='example'> <table cellspacing='0'> <thead> <tr class='odd'> <th>Title</th> </tr> </thead> <tbody> <tr class='even'> <th>Single</th> </tr> </tbody> </table> </div> On the other hand HAML reads whitespaces (like YAML): .example %table{:cellspacing => "0"} %thead %tr.odd %th Title %tbody %tr.even %th Single Furthermore its obvious that HAML is more readable because of no trailing tags. And this is the only pro for me that counts: readability. Have a look yourself: Tutorial on HAML

diagnose! BETA

Two weeks ago a colleague was showing me a diagnosis software which is for free. And as a teacher those things are good to know. Anyway I already was looking for a little project I could use to get acquainted with rails 4 and evaluating checkboxes, so I picked this one up: to do diagnoses. The project is hosted on GitHub and if others want to contribute I will have to get myself into git branches and how to merge them without harming the app. And I will deploy the app as it is to my server: app in production stage . What does it do? There are categories (has_many and belongs_to rails associations) and questions belonging to them. So far the index page will show links to the categories and clicking them will create a page with a random choice questions. These questions are displayed with checkboxes and you can evaluate them by posting you choices and get a result page. It is nothing fancy but still something I can already work with my pupils and on the way I have learned ...

rbenv rails 4 on 3.10 manjaro

After I have changed my debian server from rvm to use rbenv I gave it a shot for my local system: These commands should work: git clone https://github.com/sstephenson/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc " type rbenv" should show something like "rbenv is a function" git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash rbenv install 2.1.1 -k rbenv global 2.1.1 gem install rails   But unfortunately first ruby and then rails were not working as good on manjaro/arch as on debian. So I had to find solutions: CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline" rbenv install 2.1.1 OR (could not get console working, tried following) curl -fsSL https://gist.github.com/mislav/a18b9d7f0d...

[rails] capistrano vs mina OR rvm vs rbenv - so many problems when deploying

After I fixed one problem with my zurb foundation gem (downgrading to 5.1.1.0 worked) I ran into other problems when deploying into production environment onto my debian server. Deploying with capistrano or mina is both depending on a working ruby system with all the gems and of course bundler working in perfect harmony. Unfortunately my rvm per user installation did not work that good with my capistrano version 3. And after finding several forks on github I decided to look for alternatives, which meant other users were not happy with the original. I gave mina a try and found it different and interesting enough to use it. And mina works great except bundler was not "showing up to the party". My reason to switch back though was the ability of capistrano to roll back releases. In the end everything pointed to one black sheep: rvm. Right now I am installing rbenv which sounds promising because focussing on little things like it was intend by the UNIX founders with al...

evaluate parameters and trigger another action with its own view in rails

Looking at my last post, this is my modification: # POST /diagnoses # POST /diagnoses.json def create #flash[:message] = params[:question_ids] # ["1 2", "2 1", "3 2"] right = [] result = [] params[:question_ids].each do |p| result = p.gsub(/\s+/m, ' ').strip.split(" ") if result[1] == Question.find(result[0].to_i).right.to_s then right << result[0] end end if right.empty? r = "0" else r = right.size end flash[:message] = "Richtig sind: " + r.to_s #+ params[:question_ids].to_s + "result: " + result.to_s session[:tmp_diagnosis_raw] = params[:question_ids] session[:tmp_diagnosis_right] = right redirect_to diagnosed_diagnoses_path end def diagnosed @diagnosed_raw = session[:tmp_diagnosis_raw] @diagnosed_right = session[:tmp_diagnosi...

Evaluate checkboxes with params through post action in rails

Lately I was looking to evaluate the parameters from an post action. The background is my questions model with four answers and one column with the a pointer to the right answer. My index.html view looks like this: <%= form_tag do %> <table> <% @questions.each do |question| %> <tr> <td> <%= question.content -%> </td> <td> <%= question.answer1-%> <%= check_box_tag 'question_ids[]', question.id.to_s + '_1' -%> </td> <td> <%= question.answer2-%> <%= check_box_tag 'question_ids[]', question.id.to_s + '_2' -%> </td> <td> <%= question.answer3-%> <%= check_box_tag 'question_ids[]', question.id.to_s + '_3' -%> </td> ...

rails cms admin area with access control - side note to my latex project

Recently I started to try out rails again, now the version 4. So far I am still very pleased, but have to admit that I was out of it for too long. A lot of things have to be "normal" to be able to get the creative flow going. At this stage I am researching for most of the time. My goal is to use latex to put out pdf files. And the best solution is to create temporary folders through the ruby library and let it be controlled by rails session management. Because rails-latex seems to not fulfill my needs, a different purpose. Anyway... I stumbled over the gem rails_admin and find it very useful. You just install it, and it will create a devise setup for you and in a jiffy your app has a admin backend through which you can control EVERYTHING. Regarding the every day programmer creating apps for customers it may seem to be too much, but for me its perfect for I know what to do with the full access to all the models. Definitely easier than setting up refineryCMS or some oth...

wagn on debian 6

wagn is something cool, and this is how I installed it on debian 6.0.7: already had my server setup with apache2, passenger, rvm and postgresql ( howto ) I also installed imagemagick (in case rmagick would work with it) got to your webroot sudo git clone https://github.com/wagn/wagn.git now you have a wagn folder change permissions to have write access, e.g.: sudo chown -R foobar:www-data wagn cd wagn (or whatever foldername you want) I tried, but no, rmagick is not working, so: outcomment rmagick in Gemfile bundle install --without mysql:memcache:test:debug:development:assets bundle exec rake wagn:install change your database.yml to fit your postgresql settings and of course have a working database already set up; wagn does dropping, creating, loading schema so your database user should be granted createdb privileges bundle exec rake wagn:create and you should see the db setting up create a /etc/apache2/sites-available/wagn.domain.com ...with e.g. a virtual host: ...

debian 6 vserver - a new installation due to centOS update problem - my steps

My centOS vserver broke down after a "yum update" and even the centOS community forum could not give an answer within 24h. In my books that is poor for the almighty and stable centOS. Bare in mind that I am just a normal user of linux, no professional and definitely no expert when it comes to server, but I can read, try and share my findings: debian 6 installation steps via ssh secure your server: adduser foobar for security purposes  change /etc/sshd/sshd_conf to PermitRootLogin no now you can login as foobar and change to root via su - visudo for sudo command permissions and put this at the bottom: foobar   ALL=(ALL) ALL change hostname change hostname in /etc/hostname and in /etc/hosts reboot login via rsa key rather than password locally do ssh-keygen ssh-copy-id -i foobar@hostname... ssh now works without passwords but with keys (for easy deployment) install ruby and rails via rvm login as root always good to have: sudo apt-get install...

'new' kid on the block - wagn wiki software

Lately I was looking for a wiki software for storing tips on how to manage a server or setup some rails stuff etc. This blog is nice and fine for that, and also save from me due to some hacks or misconfiguration on my server, but also hard to find. wagn is great because it can arrange bits of data as they come along. With a blog or a typical CMS (refineryCMS is my newest adventure/project) data is structured BEFORE input is made. Have a lock: After installing it locally I was very intrigued by inline editing or the flexible browse through. But soon after that I also struggled creating my own "wagn" rather than leaving it be as default installation. On wagn.org I got help immediately and one of the founders got in contact with me by email. I found an error on the site, and also gave them my steps to install wagn on centOS 6; bottom line is that the software is kind of young, but the company behind is very eager to promote it - licensed with GPL though. So I ins...

some trouble with rails, capistrano and git

Firstly I had to adjust the HEAD of my bare repo with some brute force like: git push --force origin 688ec48e36b747b3820d55925268f51978be96d0:master After my server bare repo was up-to-date again I could go for a closer look at capistrano and deploying my rails app. Do this on your server to get some idea of the problem: tail -n 30 log/production.log It will give you the latest 30 lines of log output. For me it were two things: precompiling did not work: I had to have a closer look at my deploy.rb etc and found some big mistakes of mine. I precompiled everything and some was already done so it had e.g. sass variables and the compiler collapsed. Just try this to see if you app runs fine: RAILS_ENV=production bundle exec rake assets:precompile --trace my server app just had empty sqlite3 files so my migration did not work : Log into your server and have a look or do some migrations manually. I read this and changed my deploy.rb file so cap deploy:migrate is run everytime...

PostgreSQL

I like to go with the newest trends since I am not really held back by any production site. So I had a look around and decided to install a new database system. The first thing you might want to consider is the growing hype of NoSQL db's like mongodb, couchdb etc. But after reading this I changed my mind: you-got-nosql-in-my-postgres-using-hstore-in-rails Having done this several times before with no gain of a working db server I looked around for a decent tutorial providing me with just the right steps: install-postgresql-on-fedora-centos-red-hat-rhel There I even had the howto for my CentOS-Server after deploying with postgresql. MySQL is in the minds of people, and it deserved a spot in the light for its availability and easyness, but with the NoSQL-movement and the availability of postgresql on the web it might be good to have had a look. And since I dont really come in contact with the db but just with the ORM there is no harm done ;) PS: there is even a nic...

rails + carrierwavve + plupload = multiple file upload

Right now I am very happy! I finished my work on creating a file upload method in rails for more than one file, altogether handled by rails sessions and as objects. First I had to learn a bit more about how rails works and I achieved that by reading a lot: books, screencasts and blogs. In this blog post I like to share what I accomplished, but without the hussle of putting code blocks in here, so watch out for bold formatted text as that is the code. My goal was to have one site with just the pure option of uploading files. All file handling would be done behind the scenes by myself logging onto my server. That said you are not going to see any fancy CRUD here. Lets start then! And dont forget to versioning your app BEFORE you try something new! [e.g. git] > rails g scaffold Photo title:string Now add carrierwave to you Gemfile and run > bundle install >rails g uploader Photo Alltogether you have model, controller, views and an uploader folder with the Ph...

Agile Web Development...

...with rails. That is the title of a very nice book on ruby on rails. If you are planing on getting to grips with rails web development I highly recommend buying the book. It took me several weeks although I wasnt doing every example, just reading through. Nunja, ab hier darf es dann auch mal wieder deutsch sein. Denn obgleich ich den ganzen Tag (zumindest daheim) englisch rede und ganz intuitiv diesen Beitrag englisch startete, fällt mir das ein oder andere "schneller" ein in deutscher Sprache. Dies ist auch der Grund, weshalb ich mir ein zweites Buch zulegte, um schneller Themen aufsaugen zu können, denn die englische Sprache ist eben nicht "verdrahtet" in meinem Kopf. Ich verstehe englische Literatur, aber sobald es schwieriger wird ist das Deutsche "beeindruckender" für mein Gehirn. So legte ich mir "Ruby on Rails 3.2" von Stefan Wintermeyer zu, welches auch online unter http://ruby-auf-schienen.de/3.2/ zu lesen ist: Wenn...

Ruby on Rails Magie

Seit einiger Zeit möchte ich ein Projekt realisieren, und stolperte von Joomla zu CakePHP zurück zu Joomla, um dann bei Ruby On Rails zu landen (kurz RoR oder einfach Rails). Mittlerweile bin ich gefesselt von Rails. Aber vorweg zur Frage, was denn Rails überhaupt ist, denn darin liegt ein großer Teil der "Kraft". Ich möchte eine Internetseite programmieren, aber nicht einfach nur EINE Seite, sondern dynamisch erstellter Inhalt, der auch noch Inhalte je nach Auswahl an den Nutzer liefert. Eine typische Anwendung ist ein Online-Shop, bei welchem der Nutzer Produkte in den Warenkorb "legt", um sie dann zu bestellen bzw. gemeinsam auf einer Rechnung an den Betreiber zu schicken. Natürlich kann man dies alles "zu Fuß" machen, aber die ganzen Datenbankenrelationen im Hintergrund (Produkte, Kunden, Aufträge, Warenkörbe usw.) sind alleine schon genug, um verrückt werden zu können. Joomla ist ein bekanntes CMS und gerade in der neusten Version eine super...

rails rollback with capsitrano deployment and git

Hello geeks! When programming rails I was very releaved having git at my site. And lately I was forced to deal with git sooner than expected Normaly I end deploying with this command, and of course before that I checked my local installation: cap deploy This time I had some trouble with my asset pipeline in production mode. Mainly because of the integration of russfrisch's html5 boilerplate. It took me a while to realize my mistake with rescuing my remote installation, because I was fixing my local system with this command: git log # look for hash git reset --hard *hash* # insert you hash where to go back to cap deploy # new deployment of old version Well, this did not work.......................... I forgot the fact my remote git system is used by capistrano to deploy, so I had to set that bare repository back too: git push --force origin *hash*:master # insert the same hash, see 'git log' ...

Ruby On Rails

Die letzten Tage hatte ich hier ja einiges zum Thema RoR (RubyOnRails) berichtet, welches für die oder den einen wohl etwas zu "geeky" war. Ich hatte mich vorletztes Jahr mit CakePHP beschäftigt, und damals schon gelesen, dass es sich an RoR anlehnt, es nachahmt für PHP. Zu dieser Zeit hatte ich nur einen normalen Webhosting-Vertrag und konnte die Sprache Ruby gar nicht zum laufen bringen, so dass ich mich ebenn für CakePHP entschied. Dann kam der Sommer und ich legte alles wieder weg. Letztes Jahr dann beschloss ich, das Rad nicht neu erfinden zu wollen, und nach langer Recherche im Netz und auf amazon kaufte ich ein Buch über Joomla-Extentions. Ich hatte schon mit dem Vorgänger Mambo gearbeitet, so war mir die Architektur grob bekannt, aber seit neuestem gibt es auch bei joomla ein Framework, und das CMS baut nur noch darauf auf. Und das Programmieren von Extensions schien auch wunderbar einfach zu gehen (bis auf den Installer, wozu eine kommerzielle IDE fast nöt...