[Solved] Ruby on rails tutorial – integration test – valid/invalid user info sign failing – user_param issue?

I think you should remove params key before user parameters, e.g.: test “invalid signup information” do get signup_path assert_no_difference ‘User.count’ do post users_path, user: { name: “”, email: “user@invalid”, password: “foo”, password_confirmation: “bar” } end assert_template ‘users/new’ assert_select ‘div#error_explanation’ assert_select ‘div.field_with_errors’ end Also you can debug received parameters in controller with pry: add gem pry … Read more

[Solved] Filter an array of hashes Ruby [closed]

Let’s try this, you have this array array = [ { “10:45” => 40, “11:00” => 40, “11:15” => 40, “11:30” => 40, “13:30” = >35, “14:00” => 40, “15:00” => 40 }, { “12:00” => 38, “12:45” => 39, “13:00” => 39, “13:15” => 39, “13:30” => 39 } ] Let’s remove the duplicate … Read more

[Solved] Ruby on Rails variables, object attributes, and methods that use a : before or after them

:symbol {key: value} When the colon is before the variable / object, it denotes a “symbol”, meaning a piece of data to be placed there. The symbol can typically be used in the likes of calling an attribute (key) or in part of a hash: @user.comment[:created_at] When the colon is after the variable / object, … Read more

[Solved] How to make HTML interact with a database? [closed]

You can’t make HTML directly interacting with database. You should create server-side application, which answer queries generated by HTML forms, JS queries, etc. I am PHP developer, I like this language, so I recommend you using it in your solution. You can read about connecting PHP to MySQL database here: http://www.w3schools.com/php/php_mysql_connect.asp There you have basic … Read more

[Solved] Fast Ruby but slow Rails

1.Why “rails” command is very slower than “ruby”? ruby invokes the Ruby interpreter, which is a compiled executable. rails invokes the Ruby interpreter plus loads many Ruby libraries that need to be located then parsed by the interpreter, before executing your Rails command. So rails –version will always take longer than ruby –version because it … Read more

[Solved] How to matche all the words from a string that starts and ends with double underscore in rails [closed]

As @aspend mentioned above you will get result just by using .flatten property of array class: <% str = “Hello my name is __john__ and i am __30__ years old”%> <%=str.scan(/__(.*?)__/).flatten %> Preview: 2 solved How to matche all the words from a string that starts and ends with double underscore in rails [closed]

[Solved] Display the details of only current user who is logged in? [closed]

You need to set the associations between models After that, it could look like this: @students = @user.students.all where @user = current_user I guess. Edit: To make it failsafe: @students = @user.students.all if @user To avoid later problems set user only when its not set by the controller e.g in a user view: @user ||= … Read more

[Solved] Rails Read and Print integers on web

If you’re trying to print the output in a browser, you’ll have to attach the other essential parts of the rails flow: routes and views. The rails getting started doc walks through this pretty well. http://guides.rubyonrails.org/getting_started.html 1 solved Rails Read and Print integers on web

[Solved] First argument in form cannot contain nil or be emptyy

in db/create_post.rb t.string :title t.text :body then do rake db:migrate (it migrate schema of data base) class PostController < ApplicationController before_action :find_post, only: [:show, :edit, :update, :destroy] def new @post = Post.new end def create @post = Post.new(post_params) if @post.save redirect_to posts_path else render ‘new’ end end def show end def post_params params.require(:post).permit(:title, :body) end … Read more

[Solved] What is a RESTful style resource?

You can find a list of them here. The actions specifically are index, new, show, edit, destroy, create, update. The idea is there is a lot of boilerplate in general for these actions (find/authorize) and this aims to simplify that. solved What is a RESTful style resource?