Tag: ruby-on-rails-4

Ruby on Rails tutorial part two

I keep getting stock [sic] in a RoR tutorial. Part 1 is here. After doing that, I ran the command: rails generate devise User Not sure if that is the correct code to type as the tutorial is not clear. I’m not sure what the command does, and which files are connected to what etc. […]

incompatible character encodings: UTF-8 and ASCII-8BIT in render action

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT): app/controllers/posts_controller.rb:27:in `new’ # GET /posts/new def new if params[:post] @post = Post.new(post_params).dup if @post.valid? render :action => “confirm” else format.html { render action: ‘new’ } format.json { render json: @post.errors, status: :unprocessable_entity } end else @post = Post.new @document = Document.new @documents = @post.documents.all @document = @post.documents.build end […]

Rails API Paperclip. Uploading image converting it to base 64 and saving it and retrieving it

Hello i am creating an api using Ruby on Rails. I am using paperclip gem. I have a profile model that has an avatar. How do i go about allowing a user to upload an avatar? Currently im quite lost. Problem is i can get this architecture to work. I am quite beginner so any […]

Ruby on Rails validation by pair of properties

I need to do validation on my model on Ruby on Rails. I have model with 2 fields: user_id some_item_id And I have many rows in DB with the same user_id, but with different some_item_id. And I need avoid duplication of this some_item_id towards to specific user_id. In Rails exist some ‘magic’ validation in one […]

Add custom class to form fields

Having such form <%= form_tag ‘search’, method: ‘get’, class: ‘form-horizontal’ do %> <%= label_tag :search, ‘Enter url here’ %> <%= text_field_tag :search %> <%= submit_tag ‘Get it!’ %> <% end %> Code above adds class=’form-horizontal’ for form tag. How can I add class=’form-control’ for each input field ?

PG::ConnectionBad: PQconsumeInput() SSL error: key values mismatch

When I open a certificate with OpenSSL::PKCS12, I lose the connection with my database and occur the error: PG::ConnectionBad: PQconsumeInput() SSL error: key values mismatch. I’m doing this: myuser@developer:~/myapp$ rails c 2.2.3 :001 > OpenSSL::PKCS12.new File.read(‘/local/to/mycert.pfx’), ‘PASSWORD’ => #<OpenSSL::PKCS12:0x000000072e6808 @key=#<OpenSSL::PKey::RSA:0x000000072e67e0>, @certificate=#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name:0x000000072e6100>, issuer=#<OpenSSL::X509::Name:0x000000072e6128>, serial=#<OpenSSL::BN:0x000000072e6150>, not_before=2014-12-18 19:15:55 UTC, not_after=2015-12-18 19:15:55 UTC>, @ca_certs=[#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name:0x000000072e5c78>, issuer=#<OpenSSL::X509::Name:0x000000072e5ca0>, serial=#<OpenSSL::BN:0x000000072e5cc8>, not_before=2014-08-04 […]

Upload image post request over http to other application using Paperclip

I am able to upload image attachements using paperclip to my application. But I would like to send the image to another application via faraday connection. Other attributes are successfully sent but not the attachment image. I am not sure what I should do to achieve this.

ActionView::Template::Error: No such file or directory @ unlink_internal – C:/Users/Javi/AppData/Local/Temp/execjs201504 29-7844-j0j83vjson

When I run my tests, the controller one fails claiming that it can’t find any views/categories/new.html.erb file. This is the failure: $ rake test:controllers DL is deprecated, please use Fiddle Run options: –seed 30439 # Running: E Finished in 2.486100s, 0.4022 runs/s, 0.0000 assertions/s. 1) Error: CategoriesControllerTest#test_new: ActionView::Template::Error: No such file or directory @ unlink_internal […]

How to add dynamic select menu in search form

I followed this railscast and successfully able to display countries and cities as dynamic select menu to choose the country and city on adding new profile. I have created a controller “search_controller.rb” with index action and a view “index.html.erb” in app/views/search. Now i want to create a search form in app/views/search/index.html.erb which have Autocomplete text […]

How to transform a user input in rails 4?

I am creating an app where users could enter their name that will be returned as chemical symbols (when matching). So I managed to do in the console like: symbols = { “ac” => “Ac”, “al” => “Al”, “am” => “Al”, “br” => “Br”, “ba” => “Ba”, “cr” => “Cr” } puts “Get your chemical […]

Ruby is the best programming language in the world - Ruby on Rails.