logo
down
shadow

Rails show the user who posted the post


Rails show the user who posted the post

By : David32
Date : November 17 2020, 01:00 AM
Hope that helps So I am building an app, I have a user model managed by devise, and a post model, post belongs_to user and user has_many posts, now I have a page where I show all posts , You can do something like this
code :
<%= link_to current_user do%>
  <%= image_tag post.user.image_string %>
<% end %>
get "profile/:id" => "users#show", :as => 'profile'

<%= link_to profile_path(@user.id) do%>
  <%= image_tag post.user.image_string %>
<% end %>
#users_controller.rb
def show
  @user = User.find(params[:id])
end


Share : facebook icon twitter icon
how to show user who create the post rails

how to show user who create the post rails


By : Christtian
Date : March 29 2020, 07:55 AM
I wish did fix the issue. At the end of your view, you have post.user.email. You need to use the @user instance variable there.
code :
          <div class="col-md-6">
              <%= @post.user.email%>
          </div>
      </div>
  </div>
</div>

<%= @post.user.email%>
How to show post only to logged in user in Ruby on Rails?

How to show post only to logged in user in Ruby on Rails?


By : Sara Ahmad
Date : March 29 2020, 07:55 AM
this one helps. for that you first have to make ensure that user is logged in before it goes to your action . so you need a before filter for that . authenticate_user! is a method given by devise . so if a user is not logged in he will redirect to the sign in page automatically
code :
before_filter :authenticate_user!, only: [:posts, :entries]
@posts = current_user.posts
@post = current_user.posts.where(id: params[:id])
Facebook SDK, when user likes and comments the post we get any response to from which we posted this post?

Facebook SDK, when user likes and comments the post we get any response to from which we posted this post?


By : trashboat44
Date : March 29 2020, 07:55 AM
wish of those help Check out webhooks.
Rails - Show the users that a user has followed who have posted a book in the last month

Rails - Show the users that a user has followed who have posted a book in the last month


By : Ayanantha G
Date : March 29 2020, 07:55 AM
Hope this helps Apologies for the question, I'm still learning rails. I'm trying to show in my html - all the users that a user has started following who have posted a book within the last month (i.e. users you've followed that have recently posted a book). I've tried following the lessons I learned from this question Rails - Show the users that a user started following in the last month - but I'm not able to get it to work and get an error undefined method `books' for #. Thank you so much for your help. , First off, there is a lot you can simplify. These lines:
code :
following_ids = @user.active_relationships.map(&:followed_id)
@userfollowing = User.where(id: following_ids)
@userfollowing = @user.followed
@newpostusers = @userfollowing.joins(:books).where(books: { created_at: (Time.now - 3.month)..Time.now) } )
How to show the time of a post being posted using express

How to show the time of a post being posted using express


By : user3615574
Date : March 29 2020, 07:55 AM
wish help you to fix your issue you could use https://www.npmjs.com/package/i18n-js if you need to translate a date into anothers langages
you could also just use this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
Related Posts Related Posts :
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • One action in Rails controller sends no data back
  • Local data (JSON) in Middleman inside a different path than /data
  • How to pass numbers in an array into a SQL statement
  • ActiveAdmin - Allow non-logged-in users to view but not edit resources
  • How to refactor this Model logic in Rails
  • :readonly key of belongs_to method doesn't work
  • Create a new view in directory
  • nested resources in devise
  • Yaml value with a leading `!`
  • Rails admin show username instead of User #5
  • Can't start WEBrick with Byebug on
  • Failing Rspec test of a FactoryGirl object
  • engine yard No application found matching remotes:
  • Rails 4 sessions cookie is not set
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org