class PhotosController
def render_image
photo = Photo.find(params[:photo_id)
send_data photo.photo, type: 'image/png', disposition: 'inline'
end
end
# config/routes.rb
get '/photos/:photo_id' => 'photos#render_image'
require 'net/http'
xml_file_content = File.read("xml_file.xml")
uri = URI('https://integration.cdek.ru/new_orders.php')
res = Net::HTTP.post_form(uri, 'xml_request': xml_file_content)
puts res.body
c:\Ruby\Ruby2.3.0\bin>rake generate_secret_token
cd C:\webserver\Redmine
class News < ActiveRecord::Base
belongs_to :user, foreign_key: :login, primary_key: :login
end
class User < ActiveRecord::Base
has_many :news, foreign_key: :login, primary_key: :login
end
class CreateNews < ActiveRecord::Migration
def up
create_table :news do |t|
t.string :login, limit: 50
t.timestamps null: false
end
add_foreign_key :news, :users, column: :login
end
def down
remove_foreign_key :news, name: :login
drop_table :news
end
end
class CreateUsers < ActiveRecord::Migration
def change
create_table :users, id: false, primary_key: :login do |t|
t.string :login, limit: 50, null: false
t.timestamps null: false
end
end
end
...
redirect_to @post, :success => "Post was successfully updated"
...
It is also possible to assign a flash message as part of the redirection. There are two special accessors for the commonly used flash names alert and notice as well as a general purpose flash bucket
If you're using Windows Subsystem for Linux then there are currently some limitations on file system notifications that mean you should disable the spring and listen gems which you can do by running rails new blog --skip-spring --skip-listen.
subscriber = Subscriber.new
subscription = sub.subscriptions.build
subscription.periods.build
subscriber.save
config.active_record.logger accepts a logger conforming to the interface of Log4r or the default Ruby Logger class, which is then passed on to any new database connections made. You can retrieve this logger by calling logger on either an Active Record model class or an Active Record model instance. Set to nil to disable logging.
config.active_record.logger = Logger.new(Rails.root.join('log', 'sql.log'))
2.3.1 :029 > ActionController::RoutingError.ancestors
=> [ActionController::RoutingError,
ActionController::ActionControllerError,
StandardError, Exception, ActiveSupport::Dependencies::Blamable,
Object, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable,
V8::Conversion::Object,
JSON::Ext::Generator::GeneratorMethods::Object,
Kernel,
BasicObject]
@posts = Post.where(user_id:123).includes(:comments).where("comments.created_at IN (?) OR comments.updated_at IN (?)", Time.zone.today...Time.zone.tomorrow, Time.zone.today...Time.zone.tomorrow)
Post.where(id: 1).or(Post.where(id: 2))