Embedded rails / ruby not showing up on heroku - heroku

My rails web app isn't showing my embedded rails & ruby properly in its views when pushed to Heroku. It works fine on the localhost. For example in my nav bar:
<ul class="nav pull-right">
<li><%= link_to current_user.first_name, user_url(current_user) %></li>
<li><%= link_to "Sign Out", session_url, method: :delete %></li>
</ul>
The first link_to tag in dev displays the signed in user's first name. When pushed to Heroku it displays the link's url not the user's first name. The link works exactly the same way in both and I don't receive any errors. Additionally, on the user's profile page it doesn't display data stored in the database but in development it does properly.
I've googled around but haven't found anyone documenting a similar problem. I created a completely different heroku app and the same problem persists.
Any advice or guidance to how to fix it would be greatly appreciated!
Thank you!

There was old attr_accessors in a duplicate model that prevented the data from being saved properly but allowing the object itself to be saved. Removing this old code enabled the production version to work properly.

Related

Why does my logo fail to load after logging into Rails App?

My logo loads on my RoR application locally. When I login however, it fails to load each time. If however, I redirect to the same page, it will load again. I'm not sure I understand what the problem is.
The link to my project can be found here https://github.com/dlyons8/family-and-community.
The logo cannot be loaded because your path is being changed after successfully logging in as an user. The Sessions controller will be redirect the user to /users/:user_id.
The affected src attribute in the <img> tag contains "logo.png" so the browser tries to fetch /users/logo.png which will not succeed.
You have two options:
1) Change your logo as an asset. This is commonly used pattern for resources and helps a lot later in deployment when you change the logo for example. Move logo.png to app/assets/images and in the app/views/layouts/application.html.erb use the image_tag helper:
<%= image_tag 'logo.png', alt: 'Logo' %>
In this way, you will always get the absolute path of your logo (/assets/logo.png) and don't have to worry about where is the user actually.
2) Change the path in the <img> tag to absolute path of the logo (/logo.png) and it will try to fetch the correct file.
The 2) solution would be easier, however I strongly recommend you to get in touch with the Asset Pipeline in Rails because it really helps a lot in handling static assets for your webpage.
Also, if you encounter a non-loading asset, always check the browser's console. In Google Chrome, you can reach it by simply pressing F12 and switching to Console tab, there will be a red error message about what resource could not be loaded and why. The displayed full URL is often helps in these sneaky problems.
you need to place the images under assets/images folder
<%= image_tag ("/assets/ruby.jpeg") %>
change assets compile to true default it is false in config/environments/development.rb
config.assets.compile = true

CSRF vulnerability - Rails 3.2.9

I use rails 3.2.9 in webrick. My site seems to vulnerable to CSRF.
I have already added <%= csrf_meta_tags %> to the layout file..
And added the Protect_from_forgery in my application controller..
but when i try to make a Post request from a form in another domain, it's possible.. My site still seems to be vulnerable to CSRF..
I'm struck, wondering how to proceed! Pls help me out

Get the current page URL in Ruby/Rack

I can't seem to find an answer to what should be simple. I'm using Serve, which runs on a WEBRick server. I'd like to be able to grab the current page's URL. How would I do that?
Since Serve uses Rack under the hood, try this in a view:
<%= request.url %>

Wicked gem in rails, link_to previous_wizard_path but want to save object in between

I implemented the wicked gem and it works quite nice. Using the rails cast got it to go between parts of the various steps using link_tos. this is great but it doesn't obviously do the submit_tag like when you click "save document" at the bottom of each page... I would like something to happen to call the update method in the controller with the data from that form but I am not sure how to do this with the standard link_to and previous_wizard_path and next_wizard_path helpers, as those do not call the update but the show it seems.
So not sure, is the link_to to navigate between steps not the preferred way if data has to be saved from each form step in between?
well, usually, you use a form with submit button for each wizard step - just as in the railscast.
the use of link_to is only presented as a way for skipping steps.

Can't get rjs to work right, maybe issue with difference between link_to_remote and link_to with :remote => true

I am having problems setting rjs up and I don't know the right way to code this for rails 2.3.14
Are they (link_to_remote and link_to with :remote > true) the same or do they reflect rails versions or are they in fact different?
I am using prototype, as required by my company (so jquery is not an option).
I also see that there is link_to_function so I am really not sure what the right approach is!
link_to :remote => true is a Rails 3 convention and doesn't work in Rails 2. Since you are using Rails 2.3 you'll want to use link_to_remote for ajax calls.
link_to_function is used for when you want some javascript to run when a link is clicked and not necessarily an ajax call to the server. Stuff like showing/hiding elements on a page.

Resources