This is my first time interaction with a rails plugin and I'm unable to wrap my head around how this thing works. I'm going to make a rails plugin/engine. I want to include this plugin in my rails application(a different project), how can I do it? I found this which suggests to
At the root of this brand new engine's directory lives a plugin_name.gemspec file. When you include the engine into an application later on, you will do so with this line in the Rails application's Gemfile:
gem 'plugin_name', path: 'engines/plugin_name'
My question is that how exactly do I do it? I mean when I create a rails application I do not find any engines directory in the folder structure. And also which directories from the plugin project do I have to place in the engines/ directory?
I created a plugin by doing
rails plugin new plugin_name --mountable
and it generated following files/directories:
|-app/
|-bin/
|-config/
|-demo_project.gemspec
|-Gemfile
|-Gemfile.lock
|-lib/
|-MIT-LICENSE
|-Rakefile
|-README.md
|-test
|-dummy
|-(contains a rails application)
Now once I'm done with this plugin, how do I include this in another rails application? What directories do I need to put in engines/ in addition to including the plugin in the gemfile?
In addition to this I also want some info about what the following is indicating
Additionally, the --mountable option tells the generator to mount the engine inside the dummy testing application located at test/dummy by adding the following to the dummy application's routes file at test/dummy/config/routes.rb:
mount PluginName::Engine => "/plugin_name"
What does the mount point indicate and what will be it's role once the plugin is included in a rails application?
Rails engine is an isolated rails app, that is mounted inside main app. Two main reasons to create an engine are isolation of an application part (with possible intent to split the app into pieces) and code reuse (when you use same engine in several apps)
Technically it is a ruby gem, but often engines start (and live) as an isolated part of a larger app, without being completely extracted into own repository, gem publishing etc.
For example, if you have admin part of your app, you can make it an engine:
# in gemfile:
gem 'admin', path: 'engines/admin'
# routes:
mount Admin::Engine => '/admin'
# engine's routes:
resources :foo # => because of being in an engine this will be /admin/foo
directory structure can look like:
|-app/
|-bin/
|-...
|-config/
|-application.rb
|-routes.rb
|-engines/
|-admin_engine/
|-app/
|-controllers/admin/
|- foo_controller.rb
|-config/
|-routes.rb # <- this is engine's routes
|-lib/
|-admin/
|-engine.rb
|- admin.gemspec
I have install Spree ecommerce following this link
https://guides.spreecommerce.org/developer/getting_started_tutorial.html
all are work but canot find out the backend and frontend folder.
Can anyone teach me how to show or find out all the controller in Back end and front end
Since Spree 3.4 you can copy views (turned on by default).
rails g spree:install --migrate=false --sample=false --seed=false --copy_views=false
If you have an older version then you have to copy views from GitHub Spree repo.
Normally Rails streaming requires:
render stream: true
in a controller action. Is there any way to make that the default for the whole controller? RailsCasts says it's possible with a stream class method:
class ApplicationController < ActionController::Base
stream # doesn't work
...
end
but that's not in the official docs and on Rails 4.1, I get undefined local variable or methodstream' for ApplicationController:Class`. It would be nice to be able to declare streaming in one place in order to keep actions DRY.
The default webserver in Rails 3,WEBrick, doesn’t support streaming so to see it in action we’ll need to switch to another that does, such as Unicorn. The Unicorn gem is listed in the application’s Gemfile but it’s commented out by default. To use it we uncomment this line and then run bundle to install it.
gem 'unicorn'
Then
$ bundle install
Unicorn supports streaming but it needs to be configured. For this, you
need to create a config file as follow:
# unicorn.config.rb
listen 3000, tcp_nopush: false
And use it on initialization:
unicorn_rails --config-file unicorn.config.rb
You may also want to configure other parameters like tcp_nodelay.
Please check its documentation for more information:
If you are using Unicorn with NGINX, you may need to tweak NGINX.
Streaming should work out of the box on Rainbows.
Hope it will work
For more consider Rails streaming
I have mountable rails engine Users:
users/
...
features/
...
specs/
dummy/
controllers/
models/
factories/
...
I have a client app MySite, which uses the Users engine:
my_site/
app/
...
features/
...
specs/
controllers/
models/
factories/
...
Gemfile
Gemfile:
gem "users", git: "..."
Is it possible to run engine rspec/cucumber tests in the MySite app instead of the mock?
If so, what is the best way?
You should not do this for two reasons:
The User engine is its own project. It should work in isolation in a certain way. Adding these tests to any project the User engine is included in does not make sense. Why not run all the specs of all the gems you include in your project as well?
If you have specific acceptance criteria for your application, add cucumbers for that to your project. That way, if you decide to ditch the User engine in the future with something else, you can still verify your application behaving as expected. If you'd included the cucumbers from the engine, then those criteria would have been lost as well.
I know in PHP you have to intrepret a page like index.php, but in Ruby how does it work? I don't know what is the Ruby extension like index.php for PHP. Could you help me?
If you are talking about a command line program this will work.
puts "Hello World"
or if you want an object oriented version
class HelloWorld
def initialize(name)
#name = name.capitalize
end
def sayHi
puts "Hello #{#name}!"
end
end
hello = HelloWorld.new("World")
hello.sayHi
If you are looking for a ruby on rails version of Hello World.
Check the Getting Started Guide for Rails.
You can take a look at this Ruby Programming Wiki on Wikibooks
Code:
puts 'Hello world'
Run:
$ ruby hello-world.rb
Hello world
This is how to write a very simple "hello world" using Sinatra, which is a great way to bring up a Ruby-based website without using Rails. The sample is basically the same as the Sinatra folks have on the front page of their site. It's really this simple.
Install the Sinatra gem along with its dependencies:
`gem install sinatra`
Save this to a file called hi.rb:
require 'sinatra'
get '/hi' do
"Hello World!"
end
Drop to the command-line, and enter ruby hi.rb. After a few seconds you should see something like:
== Sinatra/1.1.0 has taken the stage on 4567 for development with backup from WEBrick
[2010-12-04 11:43:43] INFO WEBrick 1.3.1
[2010-12-04 11:43:43] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.5.0]
[2010-12-04 11:43:43] INFO WEBrick::HTTPServer#start: pid=37898 port=4567:
By default Sinatra serves its pages at port=4567, but you can change it. Read the docs to learn how.
Open a new window in your browser, and go to:
http://localhost:4567/hi
and you should see Hello World! in your browser window.
Sinatra is really easy to work with, and makes a great prototyping and light-to-medium weight MVC-like server. I love it because of its easy integration with Sequel, my favorite ORM, and HAML, which replaces ERB as the templating engine.
Sinatra's Intro doc is a great starting point. The Sinatra Book is a good resource too.
How does it work in Ruby?
Ruby is a scripting language (not compiled) just like php (as you said "you have to intrepet a page") and python, bin/bash, etc...in Ruby you have libraries with helpers and very very cool stuff they are called "gems" (Ruby and Gems :D nice name convention right? BTW this is because Ruby's parent is Perl).
You can organized different files inside one Ruby's project folder, it could be in this case one *.rb file and one "Gemfile" (that's the name without extension) in which you define which "gems" you want to install in your Ruby app (read about bundler), only with this two files you will be able to successfully do anything you want but as a desktop app (by this i mean that the Ruby app you write will only be executable on a computer with Ruby installed, and you have to install it manually (with bundler so all required "gems" are in there) and then manually run Ruby's command targeting your code's main class (unless of course you create a cron-job that do this automatically for you, pretty common practice to run processes on web servers).
If you want to use Ruby to create a "webapp" , website , etc right now two pretty popular choices are using the "rails" framework and "sinatra" gem.
With rails (that's why you hear much about ruby on rails) framework you are able to execute commands to create new website project, remember that rails uses the coding pattern called MVC (model view controller) so you will have plenty options for creating your models, views and controllers individually or using "scaffold" that will create all of them for you, rails will create a bunch of files and some of them will not be *.rb of Gemfile, all of them will have a specific task: configuration files for database, labels, of config or other "gems" you install besides rails.Take in mind that rails offer stuff for TDD (test driven development) so in a matter of hours you can have a fully functional website 100% tested and operational (big infrastructure).
This is why i also brought "sinatra" gem to this conversation...sinatra will give you same functionality than rails does but instead sinatra will not install anything for you (leaving space for error if you have not expertise on setting on web servers, web apps , etc) only the sinatra framework which will run a server for you on a specific port number so that way you can then add code to your main class in order to display HTML(small infrastructure)
What is the Ruby extension like index.php for PHP?
All ruby files are using *.rb
Hope this helps!
PS: Hello world sample
install ruby
create a new folder an inside create a file "hello.rb"
open the file and add the following code:
puts 'Hello world'
close and save the file
now open a terminal, console, etc go to your ruby file folder path and run the following command:
ruby hello.rb
that will print on your console:
Hello world
puts "Hello, World!"
To run Ruby scripts on the web, you need to use a special server, run through (F)CGI, or do some other stuff; there are several ways to get different languages HTTP-accessible. However, the simplest way is probably to use a Ruby web framework, such as Ruby on Rails or Merb -- these projects include servers and all of the things you need to get going.
Just copy and past this code on your terminal. Then hit enter.
ruby -e "puts 'Hello world'"
I know the question was talking about Ruby, but I think you meant rails (which is what it was tagged as). Rails is a web framework that uses the ruby programming language.
install rubyonrails.
Type:
rails projectname
cd projectname
ruby script/server
Navigate to http://localhost:3000