How to redirect to a permalink that is stored as a column in my model - ruby-on-rails-3

I am building something where contributors can post content to my site. I want to create a link where other users can click on and bring the user to the respective contributor's own website. The permalink for each contributor's website is a column in my contributor model.
Everything I tried so far just appends the contributor's permalink to the end of the existing URL. ie, www.mysite.com/xxx/www.contributorsite.com instead of just redirecting to www.contributorcite.com
Please help

Try something like this (should probably build the link in the controller instead of model, or just append http:// to the user entered info):
<% link = "http://"+user.permalink %>
<%= link_to "Users website", link %>

Related

How do I add google analytics code in my landing pages made using RefineryCMS?

I have one RefineryCMS application where I want to add option for creating landing pages. And in these individual landing pages there must be provision for adding unique google analytics code. But i am not able to do it as this CMS provides option for adding only one google analytics code for the entire site.
Please suggest.
Since Google Analytics is a JS script, you'll make use of yield and content_for rails helpers
in your head partial add this where you want the Google analytics code to be:
<%= yield :analytics %>
in your respective landing page(at the very top), add this:
<% content_for :analytics do %>
***Google analytics script goes here***
<% end %>
that should help

Confused why a test in section 5.3 should fail

In the Rails Tutorial, section 5.3 (Layout links) we add some tests for the Contact page:
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact'
expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
end
end
After which we comment out the Contact link in the footer code:
<li><%#= link_to "Contact", '#' %></li>
According to the text, "To ensure that both of the tests in Listing 5.17 fail, we need to comment out the “Contact” link in the footer", but that doesn't make sense to me. There is no test for the Contact link, only tests that the Contact page has valid title and content. If the Contact page is properly defined the tests should still pass whether there's a link in the footer or not.
Or am I missing something here? It behaves as I expect it to, but I don't want to just continue on and miss something I should be understanding.
Thanks
If we don't comment out the link, the first test will pass before we create our Contact page. That's because RSpec will search for the word "Contact" anywhere on the page (that's how 'have_content' works), so it will find it in the footer, which means the first test will pass thanks to our generic footer, not thanks to us actually creating a Contact page.

How to show images of links in profile

I think this is a simple problem but I do not know how to phrase it to get a sample solution from a search engine.
Instead of allowing profile image uploads/gravatars on my website I would like to store links to images in the profile db table and embed those images in the profile show page view.
My initial thought is just to have a string url filed in the db. From there I do not know how rails will parse the string url and render the image.
Any suggestions are greatly appreciated.
If you have a link to the image stored as a link on the profile, then in your view you could do something like this:
Add image_link to Profile model
In controller
def show
#profile = Profile.find(params[:id])
....
end
In view
<%= image_tag #profile.image_link %>

how to post :create from the default update url, rails 3

I'm sure this is pretty basic, but I'm somewhat new to rails and struggling to find a solution via search.
I'm implementing a message model to enable private messaging on a forum. I have the models resource nested within a users resource.
Currently the model works, but I want to enable a user to reply to a private message directly on the message show page. I.e users/1/messages/16 instead of users/1/messages/new. Currently this is the default route for 'update' within the MessagesController. Is there anyway to make the form on this page hit the 'create' action within the controller, instead of the 'update'?
Thanks.
Sure, I would try something like this:
On your show page just add a new form.
<%= form_for :message, :url => new_user_message_path do |f| %>
...
<% end %>
You can check the routes of your application using this command:
bundle exec rake routes
I suggest you to read the rails guide: http://guides.rubyonrails.org/

Rails login partial in different controller

Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need